Interface
The code is as follows:
1 UnitUnit1;2 3 Interface4 5 uses6 winapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics ,7Vcl.controls, Vcl.forms, Vcl.dialogs, vcl.stdctrls,inifiles;//Add library Inifiles8 9 typeTenTForm1 =class(Tform) One Button1:tbutton; A Button2:tbutton; - Label1:tlabel; - Label2:tlabel; the Label3:tlabel; - Label4:tlabel; - Edit1:tedit; - Edit2:tedit; + Edit3:tedit; - Checkbox1:tcheckbox; + procedureButton1Click (sender:tobject); A procedureButton2click (sender:tobject); at Private - {Private Declarations} - Public - {Public Declarations} - End; - in var - Form1:tform1; to var +FilePath:string; - Myinifile:tinifile; the Implementation * $ {$R *.DFM}Panax Notoginseng - procedureTform1.button1click (sender:tobject); the begin + Try AFilePath: = Extractfilepath (Paramstr (0)) +'Serverlist.ini';//get current path + file name theMyinifile: = Tinifile.Create(filepath);//Create a file + except -ShowMessage ('Loadini Opening configuration file failed'); $ Exit; $ End; - {Write} -Myinifile. WriteString ('ListServer1','Servercount','1'); theMyinifile. WriteString ('ListServer1','NAME0','1'); -Myinifile. WriteString ('ListServer1001','Servercount','1');WuyiMyinifile. WriteString ('ListServer1001','NAME0', edit1.text); theMyinifile. WriteString ('ListServer1001','IP0', edit2.text); -Myinifile. Writeinteger ('ListServer1001','Port0', Strtoint (Edit3.text)); WuMyinifile. Writebool ('Battle','Enable', False); - AboutMyinifile. Writeinteger ('Resolution','width',1024x768); $Myinifile. Writeinteger ('Resolution','Height',768); - ifcheckbox1.checked = True Then -Myinifile. Writebool ('Window_mode','MODE', True) - Else AMyinifile. Writebool ('Window_mode','MODE', False); +ShowMessage ('Write Success'); the End; - $ procedureTform1.button2click (sender:tobject); the begin the Try theFilePath: = Extractfilepath (Paramstr (0)) +'Serverlist.ini';//get current path + file name theMyinifile: = Tinifile.Create(filepath);//Create a file - except inShowMessage ('Loadini Opening configuration file failed'); the Exit; the End; About {Read} theEdit1.text:= Myinifile. ReadString ('ListServer1001','NAME0',"'); theEdit2.text:= Myinifile. ReadString ('ListServer1001','IP0',"'); theEdit3.text:= Myinifile. ReadString ('ListServer1001','Port0',"'); + End; - the End.
Delphi operation on INI file