[Lazarus] How to use data from stringlist in another form.

Antonio Fortuny a.fortuny at sitasoftware.lu
Wed Mar 27 09:06:31 CET 2013


Le 26/03/2013 15:14, appjaws a écrit :
> I have 2 forms, form 1 calls form 2 on a buttonclick process.
> Form 2 loads a string list, operations are carried out and the 
> stringlist is saved.

on FormMain:
...
implementation
uses
   unit2;

procedure TFrmMain.Button1Click(Sender: TObject);
begin
   if Form1.List.Count = 0 then
     Form1.LoadList;
   // do whatever do to to compare
end;
==============================================
on second form:
unit unit2;
{$mode objfpc}{$H+}
interface
uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
   { TForm1 }
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
   private
     { private declarations }
     FList: TStringList;
   public
     { public declarations }
     procedure LoadList;

     property List: TStringList read FList;
   end;

var
   Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
   FList := TStringList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   FList.Free
end;

procedure TForm1.LoadList;
begin
   FList.LoadFromFile('myfile.txt')
end;

end.

All this compiles and runs.
Do not forget to create Form1 before it is used in MainForm

Antonio.







More information about the Lazarus mailing list