I need your help.
Let's say that I have three .INI files: Default.ini, Stack.ini, and Overflow.ini. I just store Default.ini as a variable in the code. This setting of course, it will automatically load the file Default.ini every time the application is run. It's not possible to put all the file names in the code, of course.
So my problem is, when I re-run the application, I want the .ini file that loads automatically is the last recently used of .ini file.
How to do that ?
Thank you for your help and your help would be greatly appreciated!
Below is the most actual important part of my codes [based on MasterMan82's TIniFile code].
......
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, IniFiles, Dialogs;
......
private
FCurrentIniFilename: String;
......
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
I, LinesCount: Integer;
Read : TIniFile;
begin
FCurrentIniFilename := ExtractFilePath(Application.EXEName)+ 'Default.ini';
Read := TINIFile.Create(FCurrentIniFilename);
Try
Proxy.Text := Read.ReadString('SETTING','Proxy','');
Port.Text := Read.ReadString('SETTING','Port','');
Route.Checked:= Read.ReadBool('SETTING','Route',False);
// TO READ MEMO LINES
LinesCount := Read.ReadInteger('MEMO', 'Lines Count', 0);
for I := 0 to LinesCount-1 do
Memo1.Lines.Insert(I, Read.ReadString('MEMO', 'Item'+IntToStr(I), ''));
Finally
Read.Free;
end;
end;
procedure TForm1.SaveClick(Sender: TObject);
var
I, LinesCount: Integer;
ToSave : TIniFile;
begin
ToSave := TINIFile.Create(FCurrentIniFilename);
Try
ToSave.WriteString('SETTING','Proxy',Proxy.Text);
ToSave.WriteString('SETTING','Port',Port.Text);
ToSave.WriteBool('SETTING','Route',Route.Checked);
// TO SAVE MEMO LINES
LinesCount := Memo1.Lines.Count;
ToSave.WriteInteger('MEMO', 'Lines Count', LinesCount);
for I := 0 to LinesCount-1 do
ToSave.WriteString('MEMO', 'Item'+IntToStr(I), Memo1.Lines[I]);
Finally
ToSave.Free;
end;
end;
procedure TForm1.OpenClick(Sender: TObject);
var
I, LinesCount: Integer;
OpenFile : TIniFile;
begin
if OpenDialog.Execute then begin
FCurrentIniFilename := OpenDialog.Filename;
Open := TINIFile.Create(FCurrentIniFileName);
Try
Proxy.Text := OpenFile.ReadString('SETTING','Proxy','');
Port.Text := OpenFile.ReadString('SETTING','Port','');
Route.Checked:= OpenFile.ReadBool('SETTING','Route',False);
// TO READ MEMO LINES
LinesCount := OpenFile.ReadInteger('MEMO', 'Lines Count', 0);
for I := 0 to LinesCount-1 do
Memo1.Lines.Insert(I, OpenFile.ReadString('MEMO', 'Item'+IntToStr(I), ''));
Finally
OpenFile.Free;
end;
end;
end;