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. Ubuntu系统---安装 WPS

     Ubuntu系统---安装 WPS Ubuntu桌面系统自带了Libreoffice办公软件,但是个人觉得它不符合我们中国人的使用习惯.搜索了Office For Linux,好麻烦,也会出现问题, ...

  2. Mac上的redis安装与jedis入门

    Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件 安装与配置 (1) https://redis.io/download下载redis stable ...

  3. Java&Selenium&JS&AWT之那些难以点击到的按钮

    一.摘要 本篇博文的重点并不是简单的click()方法,而是要讲的是那些click()方法失效的时候的处理方式,其实做自动化久了我们都能发现研发的代码并不是都那么美丽,selenium支持的8种定位方 ...

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

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

  5. CodeForces - 113B Petr# (后缀数组)

    应该算是远古时期的一道题了吧,不过感觉挺经典的. 题意是给出三一个字符串s,a,b,求以a开头b结尾的本质不同的字符串数. 由于n不算大,用hash就可以搞,不过这道题是存在复杂度$O(nlogn)$ ...

  6. python一些方便excel行操作的函数(一)

    import collections class headhandler(): def __init__(self,mylist): self.mystorage={} self.mylist = m ...

  7. 【LuoguP4482】[BJWC2018]Border 的四种求法

    题目链接 题意 区间 boder \(n,q\leq 2*10^5\) Sol (暴力哈希/SA可以水过) 字符串区间询问问题,考虑用 \(SAM\) 解决. boder相当于是询问区间 \([l,r ...

  8. Codeforces Round #588 (Div. 2) B. Ania and Minimizing(构造)

    链接: https://codeforces.com/contest/1230/problem/B 题意: Ania has a large integer S. Its decimal repres ...

  9. python 3列表推导式的的一点理解!

    python 3列表推导式的的一点理解! Python的列表推导式对于新手来说一般都难以理解,简单看个例子: [x * x for x in range(1,100)] 上面是一个很简单的列表推导式, ...

  10. DP基础(线性DP)总结

    DP基础(线性DP)总结 前言:虽然确实有点基础......但凡事得脚踏实地地做,基础不牢,地动山摇,,,嗯! LIS(最长上升子序列) dp方程:dp[i]=max{dp[j]+1,a[j]< ...