I've cut my prog down to the bones to show you and it's now a bit messy but the problem still shows.
Running the prog gives a button to press and it opens a dialog to select a directory. Any will do. That will have written a harmless ini file (RubyEditor.ini) to the D Drive.
Label6 isn't showing.
Closing and restarting the prog will now have Label6.caption showing the previously selected directory.
Why doesn't it show the Label6.Caption:=('No Directory Found'); in FormCreate work ?
I've tried with brackets and without. I've tried setting a string outside and using a variable. All to no avail.
No doubt its a stupid mistake on my part.
Apologies if I've not put this code up right, not really sure how to do it.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
EditBtn, ExtCtrls, Menus, Inifiles;
type
{ TForm1 }
TForm1 = class(TForm)
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label6: TLabel;
Panel3: TPanel;
SelectDirectoryDialog1: TSelectDirectoryDialog;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
fnName, drName, drPath: string;
implementation
{$R *.lfm}
{ TForm1 }
procedure savetoini(const aFileName:string);
var
vIni : TIniFile;
begin
vIni := TInifile.Create('D:\RubyEditor.ini');
try
vIni.writestring('Main','CurrentPath',drName);
finally
vIni.free;
end;
end;
procedure readfromini(const aFileName:string);
var
vIni : TIniFile;
begin
vIni := TInifile.Create('D:\RubyEditor.ini');
try
vIni.readstring('Main','CurrentPath','');
finally
drName:=vIni.ReadString('Main','CurrentPath','');
vIni.free;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if SelectDirectoryDialog1.Execute then begin
drName := SelectDirectoryDialog1.FileName;
edit1.text:=drName;
savetoini('D:\RubyEditor.ini');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
readfromini('D:\RubyEditor.ini');
if drName='' then Begin
Label6.Caption:=('No Directory Found');
end;
Label6.Caption:=drName;
edit2.text:=drName;
end;
end.