Although it is convenient to use the Tinifile class, I think it is easier to use the system API to perform operations. Each read/write operation only requires one row. Code And does not need uses inifiles.
In this example:
Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; button1: tbutton; button2: tbutton; button3: tbutton; Procedure button1click (Sender: tobject); Procedure destroy (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} const filepath = 'C: \ temp \ My. INI '; // write the INI file. If the specified file path does not exist, procedure tform1.button1click (Sender: tobject); begin writeprivateprofilestring ('segment 1', 'key1 ', 'value 1', pchar (filepath); writeprivateprofilestring ('segment 1', 'key2', 'value 2', pchar (filepath); writeprivateprofilestring ('segment 2 ', 'key1', 'value 1', pchar (filepath); end; // display the Write result in memo to see procedure tform1.button2click (Sender: tobject ); begin if not fileexists (filepath) Then exit; memo1.lines. loadfromfile (filepath); end; // read Test Procedure tform1.button3click (Sender: tobject); var Buf: array [byte] of char; {prepare to accept the buffer} begin getprivateprofilestring ('segment 1', 'key2', 'default ', Buf, length (BUF), pchar (filepath); showmessage (BUF ); end; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 148 clientwidth = 237 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter pixelsperinch = 96 textheight = 13 object button1: tbutton left = 127 Top = 24 width = 98 Height = 25 caption = #20889 #20837 'ini '#25991 #20214 taborder = 0 onclick = button1click end object button2: tbutton left = 127 Top = 65 width = 98 Height = 25 caption = #30475 #30475 #20889 #20837 #32467 #26524 taborder = 1 onclick = button2click end object button3: tbutton left = 127 Top = 104 width = 98 Height = 25 caption = #35835 #21462 'ini '#25991 #20214 taborder = 2 onclick = button3click end object memo1: tmemo left = 0 Top = 0 width = 121 Height = 148 align = alleft lines. strings = ('memo1') taborder = 3 explicitheight = 183 endend
Related functions include:
Writeprivateprofilesection {} writeprofilesection {} writeprofilestring {} getprivateprofileint {} getprivateprofilesection {} getprivateprofilestruct {} getprofileint {} getprofilesection {} getprofilestring {}