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. 归并排序C程序详解

    #include <iostream> #include <cstring> #include <cstdlib> using namespace std; //归 ...

  2. 团队项目-Beta版本发布

    这个作业属于哪个课程 课程链接 这个作业要求在哪里 作业要求链接 团队名称 众志陈成 这个作业的目标 通过团队协作了解软件开发的大致流程,并在这个过程中体会调整与优化程序的方法,为以后真实的软件开发奠 ...

  3. Ubuntu系统--安装官方flash插件包的方法

    浏览器安装官方install_flash_player_npapi_linux.x86_64.tar.gz插件包的方法 第一步:下载安装包. adobe flash player的官方下载instal ...

  4. OSI七层协议和TCP/IP四层协议

    1. OSI七层和TCP/IP四层的关系 1.1 OSI引入了服务.接口.协议.分层的概念,TCP/IP借鉴了OSI的这些概念建立TCP/IP模型. 1.2 OSI先有模型,后有协议,先有标准,后进行 ...

  5. 牛客练习赛42 C 出题的诀窍 (贡献,卡常)

    牛客练习赛42 C 出题的诀窍 链接:https://ac.nowcoder.com/acm/contest/393/C来源:牛客网 题目描述 给定m个长为n的序列a1,a2,-,ama_1 , a_ ...

  6. 微信小程序开发框架 Wepy 的使用

    一.github地址:https://github.com/Tencent/wepy 按照 README.md 的步骤进行操作: 1.在“介绍”中获得 wepy 的开发资源汇总:https://git ...

  7. DAG及拓扑排序

    1.有向无环图和拓扑排序 有向无环图(Directed Acyclic Graph,简称DAG):拓扑排序指的对DAG一个有序的线性排列.即每次选出一个没有入度的节点,然后输出该点并将节点和其相关连的 ...

  8. Linux文件系统之目录管理mkdir命令

    mkdir命令 mkdir命令mkdir命令简介mkdir命令用来创建指定的名称的空目录,要求创建用户在当前目录具有权限,并且制定的目录名不能是当前目录中已有的目录. 命令格式mkdir [选项] [ ...

  9. UVA10900 So you want to be a 2n-aire?

    So you want to be a 2n-aire? PDF 在一个电视娱乐节目中,你一开始有1元钱.主持人会问你n个问题,每次你听到问题后有两个选择:一是放弃回答该问题,退出游戏,拿走奖金:二是 ...

  10. 【CF1218E】Product Tuples

    题目大意:给定一个长度为 \(N\) 的序列,求从序列中选出 \(K\) 个数的集合乘积之和是多少. 题解: 由于是选出 \(K\) 个数字组成的集合,可知对于要计算的 \(K\) 元组来说是没有标号 ...