I know it's simple but can't find solution :|
I want to create program that have one form with few Edit boxes and two buttons.
One button runs procedure from other unit. This procedure is SaveIni(ed1,ed2,ed3:string); and it saves to ini file whatever is in Edit1, Edit2 and Edit3. It works fine. Problem appears when I want to use another procedure in Unit2 with which I want to load data from that ini file into variables and then sets Edit4,Edit5 and Edit6 text to those variables. It is called LoadIni(ed1,ed2,ed3:string);.
Here's the code for both units (Unit1 and Unit2):
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,inifiles;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
edd1,edd2,edd3:string;
implementation
uses
Unit2;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
saveini(edit1.text,edit2.text,edit3.text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
loadini(edd1,edd2,edd3);
edit4.text:=edd1;
edit5.text:=edd2;
edit6.text:=edd3;
end;
end.
unit Unit2;
{$mode objfpc}{$H+}
interface
procedure loadini(ed1,ed2,ed3:string);
procedure saveini(ed1,ed2,ed3:string);
implementation
uses
Classes, SysUtils,Inifiles;
var
inifig:Tinifile;
const
defEd1='100';
defEd2='200A';
defEd3='300 sad';
procedure loadini(ed1,ed2,ed3:string);
begin
iniFig:=TIniFile.Create('config.ini');
ed1:= iniFIG.ReadString('PATHS','ed1',defEd1);
ed2:= iniFIG.ReadString('PATHS','ed2',defEd2);
ed3:= iniFIG.ReadString('PATHS','ed3',defEd3);
inifig.free;
end;
procedure saveini(ed1,ed2,ed3:string);
begin
iniFig:=TIniFile.Create('config.ini');
iniFIG.WriteString('PATHS','ed1',Ed1);
iniFIG.WriteString('PATHS','ed2',Ed2);
iniFIG.WriteString('PATHS','ed3',Ed3);
inifig.free;
end;
end.
And this is Ini file
[PATHS]
ed1=Edit1
ed2=Edit2
ed3=Edit3