uses
,inifilesvar
var
LanguageINI: TiniFile;
FormSection: string;
FormStart
//轉換語言
FormSection := 'Main';
LanguageINI := TiniFile.Create(ChangeFileExt(Application.ExeName, gstr_Language + '.lng'));
fmMain.Caption := LanguageINI.ReadString(FormSection, 'L1', '');
LanguageINI.Free;
出處:
首先在Interface的Uses部分增加“IniFiles”单元
声明INI文件实例的方法是在Var中使用:myinifile:Tinifile;
打开INI文件:myinifile:=Tinifile.create('./配置文件.ini'); “./”表示当前路径
读取INI文件:
有三种函数来读取
ReadString,ReadInteger,ReadBool
格式:Function ReadString (const section,ident,Default:string):string;override;
section为小节名,Ident为关键字名,Default是当小节或关键字不存在时的缺省值
写INI文件:
有三种函数来写入
WriteString,WriteInteger,WriteBool
格式:Function WriteString (const section,ident,Value:string):override;
section为小节名,Ident为关键字名,Value是要写入的值
删除关键字:
Procedure DeleteKey (const section,ident:string);override;
删除小节:
procedure EraseSection(const Section:string);override;
例如:
Var
T: tinifile;
str: String;
Begin
T := tinifile.Create('./test.ini');
str :='ini';
t.WriteString(str,'string','aaa'); //写入
t.readstring(str,'string','bbb'); //读取
Memo1.text:=t.readstring(str,'string','aaa');
end;