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. CentOS7 字体安装卸载

    CentOS7 默认安装有 Fonts 程序, 所以能直接双击打开字体文件, 并且可以直接点击上图的 Install 按钮安装字体.采用这种安装方法,字体会被安装在 ~/.local/share/fo ...

  2. [USACO14OPEN]GPS的决斗Dueling GPS's

    题目概况 题目描述 给你一个\(N\)个点的有向图,可能有重边. 有两个\(GPS\)定位系统,分别认为经过边\(i\)的时间为\(P_i\),和\(Q_i\). 每走一条边的时候,如果一个系统认为走 ...

  3. C++踩坑记录(一)std:;string的析构

    之前写服务端程序有一个往消息队列里面推json的过程,然后发现推进去C#端取到的无论如何都是个空指针 简单复现一下现场 string str1 = string("hello1") ...

  4. stm32——modbus例程网址收藏

    https://blog.csdn.net/baidu_31437863/article/details/82178708 STM32(五) Modbus https://blog.csdn.net/ ...

  5. struts2提交表单注意事项 (3)

    供应商模块 需求:实现供应商的列表.添加.修改.删除三个功能 注意:修改时,不允许修改供应商编号 添加时,不允许显现的添加供应商编号 删除时,进行逻辑删除(根据主键将该条数据不再显示在列表) 物理删除 ...

  6. [Cypress] Find Unstubbed Cypress Requests with Force 404

    Requests that aren't stubbed will hit our real backend. To ensure we've stubbed all our routes, we c ...

  7. ajax+批量下载文件

    用过浏览器的开发人员都对大文件上传与下载比较困扰,之前遇到了一个php文件夹上传下载的问题,无奈之下自己开发了一套文件上传控件,在这里分享一下.希望能对你有所帮助.此控件PC全平台支持包括mac,li ...

  8. Crash的数字表格 / JZPTAB

    https://www.cnblogs.com/peng-ym/p/8666124.html #include<bits/stdc++.h> #define LL long long #d ...

  9. vue-cli3项目首页加载速度优化(cdn加速,路由懒加载,gzip压缩)

    今天打算上线vue的单页面项目,上线后,首页加载速度巨慢! 原因是项目上线后,网速不够快,加载js,css等资源很慢, 打开打包好的文件发现chunk-vendors.xxxxxxx.js的包很大,达 ...

  10. libpng warning: iCCP: known incorrect sRGB profile告警处理

    在 qt中加载某些 png图片会出现:libpng warning: iCCP: known incorrect sRGB profile   告警信息. 虽然没什么影响,但是总看到这个警告非常的不舒 ...