Har du Create'et din Ini-fil? Det kunne nemlig godt lyde som om det var hvad der var galt...
Her er et rigtig godt eksempel, tyvstjålet fra hjælpen:
This example reads the Transfer section of the DELPHI32.INI file into a memo and changes one of the strings in the INI file when Button1 is clicked. When Button2 is clicked, the DELPHI32.INI file is restored to its initial state, using the values stored in the memo. Before you run this example, you must add the IniFiles unit to the uses clause of your unit.
Warning: Do not click button2 before you have clicked button1!
procedure TForm1.Button1Click(Sender: TObject); var DelphiIni: TIniFile; begin DelphiIni := TIniFile.Create('c:\windows\delphi32.ini'); Memo1.Clear; DelphiIni.ReadSectionValues('Transfer', Memo1.Lines); if Memo1.Lines.Values['Title1'] <> 'Picture Painter' then DelphiIni.WriteString('Transfer', 'Title1', 'Picture Painter'); DelphiIni.Free; end;
procedure TForm1.Button2Click(Sender: TObject); var DelphiIni: TIniFile; begin DelphiIni := TIniFile.Create('c:\windows\delphi32.ini');
{ if the entry wasn’t there before, delete it now } if Memo1.Lines.Values['Title1'] = '' then DelphiIni.DeleteKey('Transfer', 'Title1') { otherwise, restore the old value } else DelphiIni.WriteString('Transfer', 'Title1', Memo1.Lines.Values['Title1']); DelphiIni.Free; end;
Det jeg altså tror du mangler er det her:
var ini: TIniFile; begin ini := TIniFile.Create(ExtractFilePath(Application.ExeName)+'MinIniFil.ini'); end;
Når du så har create'et den er det en god ide lige at kalde Update også...
Altså Ini.Update;
Når du er færdig med at bruge programmet skal du også lige huske at Free'e den... Ini.Free;
Det kan være en god ide at have Ini som en global variabel, hvis den f.eks. skal gemme og hente program indstillinger ved FormCreate og FormClose...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.