Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / QIniFile / ReadMe.Doc.txt

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
QIniFile:

QIniFile allows a RapidQ program to read/write/edit an .ini file

Version 1

In Chapter 10.6 of the RapidQ documentation, there is reference to making a custom Inifile object.
I didn't see anything like it within the RapidQ files section so it seemed appropriate to supply such.
I hope it is of some value.

I recognize that a more complete editing system can be produced but the value of QIniFile is that it
is to be utilized within a RapidQ program. Feel free to design your own.

I used the win.ini file as an example to explain QIniFile's properties, etc.
Please DO NOT play around with this file.  The WINDOWS OS can become quite inoperable when it is ill-configured.

Version 1.1

I have fixed a couple of documentation errors and added a way to reference the RapidQ.ini CONST variables.
This can be valuable if you are using them in a configuration file, ie: Formcolor=clBlue.
The value of clBlue would be zero because it is read in as a string.  To overcome this, your program will need:

MyColorString = MyIniFile.ReadEntry(MySection,Formcolor]
MyColorValue  = RQValue(MyColorString)

or more simply...

MyColorValue  = RQValue(MyIniFile.ReadEntry(MySection,Formcolor))

To use this function, your program must FIRST call the sub RQStart which reads in the RAPIDQ.Ini file and
initializes the arrays RQWORDS and RQValues.  You need to do this only once, preferably near the beginning of
your program.  RQStart needs one parameter - the exact file name you have given your 'RapidQ.inc'.

Study the code and you will see that it reads only the CONSTs and ignores all comments, etc.  Further, all hex
values are changed to decimal.  The only values NOT read in is the QBColor array.  Add in your own CONSTs but beware
that the RQWords and RQValues arrays are presently set to 450.  This can easily be changed.
 
If you are using RapidQ.inc's CONSTs within your program, and you probably are, you still must $Include <RapidQ.inc>.

Version 1.2

The QIniFile.WriteSection can add empty lines depending on where it is being written in the .ini file.  To correct this I coded a small segment '.ClearEnding' which is used internally within the program.  When referencing the 'Entry' I changed the LEN concept to an Equ$ function to ensure that a 'Section' search could not mis-interpret an 'Entry' and vice versa.

I also completly recoded the RQValue making it simpler to use.  No size parameter is needed to start. Just add in:

Create RConst As RQConst
   FileId = "QLibrary.Inc"
   Initialize
End Create

Utilize by RConst.ValueOf(Const) to get a numerical value.  It wiil also 'Execute' the RapidQ's RGB so that something like "CONST clYellow = RGB(255,255,000)" will result in the appropriate numerical value.

Contact: StarBase12@MyRealBox.com
 
Included Files:

Readme.Doc         <==== You are reading it.
QLibrary.inc       <==== A beginning effort to organize my own programming routines, functions, etc.
                         which includes QIniFile.  If someone knows a better way of coding I'd appreciate knowing how.
QLibrary.ini       <==== Has one entry which QIniFile uses to identify an editor for itself.
                         Currently set to Notepad.exe.  The whole RapidQ defaults could read in via QIniFile
                         to customize one's own projects. 

QIniFile Properties:
Field      Type            Description           
Name       String          IniFile name               
Lines      QStringList     IniFile section read
LineCount  Integer         IniFile section No. of Lines  (Use for READ ONLY!)

QIniFile Methods:
Method:         ClearEnding
Type:           Sub
Description:    Clears QIniFile.Lines of empty linefeeds
Example:        None needed.  Used internally

Method:         AddBrackets$
Type:           Function(Section As String) As String
Description:    Adds [] if needed, used internally within QIniFile
Example:        MyVariable$ = AddBrackets$("Desktop") results to "[Desktop]"

Method:         ReadEntry
Type:           Function(Sections As String,KeyWord As String) As String
Description:    Returns the [Section] keyword entry
Example:        MyVariable$ = ReadEntry("Desktop","Wallpaper") results to "(None)"

Method:         ReadSection
Type:           Sub(Section As String)
Description:    Reads in an entire [Section] to the QIniFile.Lines
Example:        ReadSection("Desktop") results to "Wallpaper=(None)","TileWallpaper=0","WallpaperStyle=2","Pattern=(None)"

Method:         WriteEntry
Type:           Sub(Section As String, KeyWord As String, Entry As String)
Description:    Writes the [Section] KeyWord=Entry to the Inifile.
Example:        WriteEntry("Desktop","TileWallpaper","1") results to the Inifile having "[Desktop]" with "TileWallpaper = 1"

Method:         WriteSection
Type:           Sub(Section As String, SectionList As QStringList)
Description:    Writes the entire [Section] & SectionList to the Inifile.
Example:        WriteSection("Desktop",SectionList)

Method:         Edit
Type:           Sub
Description:    Brings up a user defined editor to access the Inifile. (See QLibrary.ini)
Example:        Edit

QIniFile Events:
NONE


Sample code:

$INCLUDE   <RAPIDQ.INC>    ' From William Yu (Rapid-Q Creator)
$INCLUDE   <QLIBRARY.INC>  ' This could easily be added into the RAPIDQ.INC instead
                           ' but it is too easy to 'accidently' change something...
                           ' Adage: If it works don't touch it!

Declare Sub SaveToMyFile
Declare Sub CopyToMyEdit

Dim MySectionContent As QStringList
Dim I As Integer

Create MyForm As QForm
   Create MyEdit As QRichEdit
   End Create
   Create SaveButton As QButton
      Align   = alNone
      Height  = 24
      Width   = 100
      Top     = 0
      Left    = 212
      Caption = "SAVE"
      OnClick = SaveToMyFile
   End Create
   Center
End Create

Create MyIniFile As QIniFile
   Name = "C:\Windows\Win.ini"
   ReadSection "Desktop"
End Create
CopyToMyEdit

MyForm.ShowModal

Application.Terminate

'-----------------Sub Routines-------------------
Sub CopyToMyEdit
   For I = 0 To MyIniFile.LineCount - 1
      MyEdit.AddString MyIniFile.Lines.Item(I)
   Next I
End Sub

Sub SaveToMyFile
   MySectionContent.Clear
   For I = 0 To MyEdit.Linecount -1
      MySectionContent.AddItems MyEdit.Line(I)
   Next I
   MyIniFile.WriteSection "Desktop",MySectionContent
End Sub

'**********************EOF*************************

Note:

QIniFile uses Trim$, CatStr$, Equ$ functions which are included in the early subroutines.
The RQValue function utilizes a StrSeach function which is also coded in earlier.

'*************************************End Of ReadMe.Doc***************************
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-4-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-01-15 20:37:56