INI file system configuration read delphi

INI file system configuration delphi read 

a calling unit built delphi 
uses  System.IniFiles;
 . 1 , using the class TIniFile
 2 , the main class TIniFile methods and functions:
 { $ IFDEF MSWINDOWS } { TIniFile - Encapsulates the Windows INI File The interface (the Get / SetPrivateProfileXXX Functions) } 
  TIniFile = class (TCustomIniFile)
   public destructor the Destroy ; the override ;
     function the ReadString ( const Section, Ident, the Default: String ): String ; the override ;
     Procedure WriteString (
  

     const Section, Ident, Value: String); override;
    procedure ReadSection(const Section: string; Strings: TStrings); override;
    procedure ReadSections(Strings: TStrings); override;
    procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
    procedure EraseSection(const Section: string); override;
    procedure DeleteKey(const Section, Ident: String); override;
    procedure UpdateFile; override;
  end;
{$ELSE}
  TIniFile = class(TMemIniFile)
  public
    constructor Create(const FileName: string; const Encoding: TEncoding;
      CaseSensitive, UseLocale: Boolean); overload; override;
  end;
{$ENDIF}

二、读写ini
2、INI文件的格式:
[FDConnectionDefs.ini]
Encoding=UTF8

[TCPServer]
ServerName=192.168.3.100
Post=211
ChannelID=Channel1
ManagerID=Client_1

[MSSQL]
Server=119.29.5.177
User_Name=sa
Password=admin81
DATABASE=disp_tiyuxueyuan2015
DriverID=MSSQL
Pooled=True
MonitorBy=Remote
Address=119.29.5.177,1433

3, Initializing an instance of class files TIniFile: 
  compile distribution application, APP writes a first default ini file, and then read and write to: 
3.1 , MSWINDOWS
 var the IniFile: TIniFile; 
    FileName: String ; aServerName: String ;
 // FileName : you want to read ini file name 
// the Create: for initializing an instance of class files TIniFile: 
the IniFile: = TIniFile. the Create (fileName); 
aServerName: = IniFile.ReadString ( ' the TCPServer ' , ' ServerName ' , '' );
 // ... 
IniFile.Free; 


3.1 . 1Which ReadString (read document), WriteString (write files), DeleteKey (mark delete files) Common: 
meaning of its parameters: 
Section: representatives of INI file to [] split blocks: for example, the above [TCPServer] 
Ident: sign parameters 
value: value of the parameter (write) 
the Default: value of the parameter (read) 

3.2 , other platforms
 var IniFileStream: TIniFile; Encoding: TEncoding; 
    FileName: String ; AStringList: TStringList; AName: String // FileName: you read ini file name 
// the Create: for initializing an instance of the class file TIniFile: 
Encoding: = TEncoding.Unicode; 
IniFileStream: . = TIniFile the Create (fileName, Encoding, to false, to true); 

AStringList: . = a TStringList the Create ;
AStringList.LoadFromFile (FileName); 

  // / <Summary> 02, the character string is acquired myDelimiter delimited delimited values, </ Summary> 
  // / <Summary> and assign it to a TStringList: </ summary> 
  AName: = '' ; myStr: = AName; 
  
  // write a generic Procedure myItems_Delimiter // (myStr: String; myDelimiter: Char; AStringList: a TStringList); 
  myItems_Delimiter (AName, ' [ ' , AStringList);
   // for AName operation (by newline wherein each row of the sub-stream analysis, then the '=' KEY sub-stream analysis and the Value) .trim: 
// or AStringList loop through read and write operations may be performed: // AStringList.Sorted: Boolean ; // AStringList.Find (const S: String; var Index: Integer): Boolean //
  
  
  
  AStringList.IndexOf (const S: String): Integer; 
  // AStringList.IndexOfName (const the Name: String): Integer; 
  // AStringList.Add (const S: String): Integer; 
  // AStringList.Insert (Index: Integer; S const: String); 
  // AStringList.Delete (Index: Integer); 
  // AStringList.Exchange (Index1 is, Index2 is: Integer);  

AStringList.SaveToFile (FileName); 

// IniFileStream TMemIniFile inherited by inheritance from TCustomIniFile 
  { TMemIniFile - loads AN entire INI file iNTO memory and android.permission All operations to BE performed oN the memory Image. 
    of the Image CAN the then BE written OUT to the Disk file } 
  { TMemIniFile - entire INI file is loaded into memory, and all operations are allowed in the memory image (memory stream). 
  memory image (memory current) can be read like a disk file operations } //
     constructor the Create (const FileName: String; const Encoding: TEncoding; 
      // the CaseSensitive, useLocale: Boolean); overload; the override; 

3.2 . . 1 , wherein the following construct deconstruction and the attribute is other than the above TCustomIniFile inheritance: 

      constructor  the Create (the CaseSensitive, useLocale: Boolean);
       destructor  the Destroy ; the override ;
       Procedure the Clear;
       function the Remove ( const Key: String ): Boolean;
       property the Count: Integer Read the GetCount;
       property the CaseSensitive: Booleanthe Read GetCaseSensitive the Write setCaseSensitive;
       Property useLocale: Boolean the Read GetUseLocale the Write SetUseLocale;
 ---------------------  
Author: pulledup 
Source: CSDN 
Original: HTTPS: // blog.csdn .net / pulledup / article / details / 93076568 
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

 

Guess you like

Origin www.cnblogs.com/jijm123/p/11297264.html