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. 【cli命令集】

    1.调高bug等级 查看现在蜂窝目前sla情况 ROUTER> enable ROUTER# core set debug 18Core debug was 0 and is now 18Cor ...

  2. SPI使用笔记ADS1259+AD5676

    SPI的通信速率通常比较快.目前用到的ADS1259芯片,可以达到2-4MHz,可能可以更加快.一般spi都是从慢速开始调试,但是具体到某个芯片,应该核对芯片时序图,比如ti的ds1259,数据手册上 ...

  3. hivesql之 table名 with as 转储

    可能某个子查询在多个层级多个地方存在重复使用的情况,这个时候我们可以使用 with as 语句将其独立出来,极大提高SQL可读性,简化SQL~ 注:目前 oracle.sql server.hive等 ...

  4. [AngularJS] Decorator pattern for code reuse

    Imaging you have a large application, inside this large application you have many small individual a ...

  5. spring容器的refresh方法分析

    spring源码版本5.0.5 Spring容器创建之后,会调用它的refresh方法刷新Spring应用的上下文. 首先整体查看AbstractApplicationContext#refresh源 ...

  6. MFC 可编辑文本框,MFC控件关联变量总结

    Edit Control控件,默认状态下,按回车会调用OnOK()关闭窗体.解决此bug可以,类视图中单击CMFCApplication3Dlg,下方重写OnOK(),注释掉其中的代码即可. Edit ...

  7. Luogu P1110 [ZJOI2007]报表统计 multiset

    沿用了学长的$multiset$ 然后这道题可以看到我的程序中有两行注释,它在我看来和他们下面的代码没区别,但是我们发现,C++会先调用后面的参数,所以$--it$会被先执行 ... ... ... ...

  8. Unknown property 'mybatis-plus' yml文件报错

    就是因为没有对应的依赖 package com.taotao.config; import org.mybatis.spring.annotation.MapperScan; import org.s ...

  9. Eclipse 导入项目

  10. Codevs 1404 字符串匹配(Kmp)

    1404 字符串匹配 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你两个串A,B,可以得到从A的任意位开始的子串和B匹配的 ...