delphi读写INI系统配置文件

一、调用delphi内建单元
uses System.IniFiles;
、使用类TIniFile
、类TIniFile的主要方法和函数:
{$IFDEF MSWINDOWS}
  { TIniFile - Encapsulates the Windows INI file interface (Get/SetPrivateProfileXXX functions) }   TIniFile = class(TCustomIniFile)
  public
    destructor Destroy; override;
    function ReadString(const Section, Ident, Default: string): string; 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
、INI文件的格式:
[FDConnectionDefs.ini]
Encoding=UTF8 [TCPServer]
ServerName=192.168.3.100
Post=
ChannelID=Channel1
ManagerID=Client_ [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, 、初始化TIniFile文件类的一个实例:
  编译分发应用时,先写入APP一个默认ini文件,然后对其进行读写操作:
3.1、MSWINDOWS
var IniFile: TIniFile;
    FileName: string; aServerName: string;
//FileName: 你要读写的ini文件名
//Create:用于初始化TIniFile文件类的一个实例:
IniFile := TIniFile.Create(FileName);
aServerName := IniFile.ReadString('TCPServer', 'ServerName', '');
//...
IniFile.Free; 3.1.、其中ReadString (读文件)、 WriteString (写文件) 、 DeleteKey (删除文件中的标志) 常用:
其参数含义:
Section:代表INI文件中以[]分割的区块:比如上面的[TCPServer]
Ident:参数的标志
Value:参数的数值(写)
Default:参数的数值(读) 3.2、其它平台
var IniFileStream: TIniFile; Encoding: TEncoding;
    FileName: string; AStringList:TStringList;  AName: string; 
//FileName: 你要读写的ini文件名
//Create:用于初始化TIniFile文件类的一个实例:
Encoding:= TEncoding.Unicode;
IniFileStream := TIniFile.Create(FileName,Encoding,false,true); AStringList:=TStringList.Create;
AStringList.LoadFromFile(FileName);   ///<summary>02、字符串被myDelimiter字符符号分隔符分割的数值获取,</summary>
  ///<summary>并将其赋值给一个 TStringList:</summary>
  AName:='';  myStr:=AName;
  
  //写一个通用的//procedure myItems_Delimiter(myStr:String; myDelimiter:Char; AStringList:TStringList);
  myItems_Delimiter(AName,'[',AStringList);
  //对AName.Trim进行操作(通过其中换行符就子串解析每一行,再用'='号子串解析KEY及Value):   //或AStringList循环遍历进行读写操作也可:
  //AStringList.Sorted: Boolean;
  //AStringList.Find(const S: string; var Index: Integer): Boolean
  //AStringList.IndexOf(const S: string): Integer;
  //AStringList.IndexOfName(const Name: string): Integer;
  //AStringList.Add(const S: string): Integer;
  //AStringList.Insert(Index: Integer; const S: string);
  //AStringList.Delete(Index: Integer);
  //AStringList.Exchange(Index1, Index2: Integer);  AStringList.SaveToFile(FileName); //IniFileStream通过继承TMemIniFile继承TCustomIniFile而来
  { TMemIniFile - loads an entire INI file into memory and allows all operations to be performed on the memory image.
    The image can then be written out to the disk file }
  {TMemIniFile -整个INI文件加载到内存中,并允许执行所有操作在内存映像(内存流)。
  内存映像(内存流)可以进行读写等磁盘文件操作}
    //constructor Create(const FileName: string; const Encoding: TEncoding;
      //CaseSensitive, UseLocale: Boolean); overload; override; 3.2.、其中以下构建解构及属性方法是上述TCustomIniFile继承以外的:       constructor Create(CaseSensitive, UseLocale: Boolean);
      destructor Destroy; override;
      procedure Clear;
      function Remove(const Key: string): Boolean;
      property Count: Integer read GetCount;
      property CaseSensitive: Boolean read GetCaseSensitive write SetCaseSensitive;
      property UseLocale: Boolean read GetUseLocale write SetUseLocale;
---------------------
作者:pulledup
来源:CSDN
原文:https://blog.csdn.net/pulledup/article/details/93076568
版权声明:本文为博主原创文章,转载请附上博文链接!

delphi读写INI系统配置文件的更多相关文章

  1. 纯C#的ini格式配置文件读写

    虽然C#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧,其他人写的都是调用非托管kernel32.dll.我也用过 但是感 ...

  2. c#读写ini配置文件示例

    虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧     其他人写的都是调用非托管kernel32.dll.我也用过 ...

  3. C# 读写 ini 配置文件

    虽说 XML 文件越发流行,但精简的 ini 配置文件还是经常会用到,在此留个脚印. 当然,文中只是调用系统API,不会报错,如有必要,也可以直接以流形式读取 ini文件并解析. /// <su ...

  4. 自己写的 读写 ini 配置文件类

    /// <summary> /// 不调用系统API 读写 ini 配置文件 /// </summary> public class RW_ini { #region ==== ...

  5. 引用“kernel32”读写ini配置文件

    引用"kernel32"读写ini配置文件 unity ini kernel32 配置文件  引用"kernel32"读写ini配置文件 OverView ke ...

  6. C# 文件的一些基本操作(转)//用C#读写ini配置文件

    C# 文件的一些基本操作 2009-07-19  来自:博客园  字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...

  7. C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()

    转载: 1.https://blog.csdn.net/fengbingchun/article/details/6075716 2. 转自:http://hi.baidu.com/andywangc ...

  8. 使用C#读写ini配置文件

    INI就是扩展名为"INI"的文件,其实他本身是个文本文件,可以用记事本打工,主要存放的是用户所做的选择或系统的各种参数. INI文件其实并不是普通的文本文件.它有自己的结构.由若 ...

  9. C语言ini格式配置文件的读写

    依赖的类 /*1 utils.h *# A variety of utility functions. *# *# Some of the functions are duplicates of we ...

随机推荐

  1. java 中 IO 流分为几种?(未完成)

    java 中 IO 流分为几种?(未完成)

  2. 算法9-----输出全排列(递归)---移除K个数,剩下最小数。

    1.题目:给定一个字符串,输出所有的字典序. 如: 输入字符串:'ac',输出:['ac','ca'] 输入字符串:‘abc' ,输出:['abc','acb','bac','bca','cab',' ...

  3. ICPC2019徐州站游记

    day0 出师不利 差两分钟没赶上高铁回去我一定每天都到下边玩跑步 改签成卧铺,原来3点发7点到现在11点发9点到 本来计划火车上3个人练习一场,晚上宾馆还可以cf 结果全泡汤了,在火车站浪了一晚上 ...

  4. Java&Selenium自动化测试之数据驱动

    一.摘要 本片博文以四个方式展示自动化测试的数据驱动,数组.CSV.Excel.Mysql 二.TestNG&Csv&Driven package testNGWithDataDriv ...

  5. Redis数据类型操作说明

    List数据操作 lpush 语法:lpush key value [value…] 作用:将一个或多个值 value 插入到列表 key 的表头(最左边),从左边开始加入值,从左到右的顺序依次插入到 ...

  6. string::begin

    iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_ite ...

  7. 在Visual Studio Code 运行 webpack ./src/main.js --output-filename ./dist/bundle.js --output-path . --mode development 提示 Module no t found:Error:Can't resolve' 'jquery' 是因为vs code还没安装jquery

    在Visual Studio Code 运行 webpack ./src/main.js --output-filename ./dist/bundle.js --output-path . --mo ...

  8. mysql基础_数据类型

    1.数字 (1)tinyint(小整数值) 范围:有符号(-128,127) 无符号(0.255) (2)int(大整数值) 范围:有符号  (-2 147 483 648,2 147 483 647 ...

  9. C# 集合(9) 持续更新

    数组的大小是固定的.如果元素个数动态,就使用集合类. List<T>是与数组相当的集合类.其他的集合:队列.栈.链表.字典和集. .NET Framework 1.0 包括非泛型集合类,如 ...

  10. 01 salt平台,软件架构图

    1.前期调研 1.别人家的 https://www.cnblogs.com/ssyfj/p/9060367.html#top https://www.cnblogs.com/evilliu/artic ...