Poradziłem już sobie z tym wcześniej, ale dziękuję za gotowy przykład. Dla Lazarusa i systemu Linux są wymagane pewne zmiany:
{$mode objfpc}{$H+}
{$define UseCThreads}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Unix;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TWatek1 = class(TThread)
private
FFileIndex: integer;
procedure FSyncShowMessage;
protected
procedure Execute; override;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Instrukcja1 : TWatek1;
begin
Instrukcja1 := TWatek1.Create(False);
end;
{ TWatek1 }
procedure TWatek1.Execute;
begin
FreeOnTerminate := True;
fpsystem('echo "Instrukcja 1" > instrukcja1.txt');
FFileIndex := 1;
Synchronize(@FSyncShowMessage);
fpsystem('echo "Instrukcja 2" > instrukcja2.txt');
FFileIndex := 2;
Synchronize(@FSyncShowMessage);
end;
procedure TWatek1.FSyncShowMessage;
begin
ShowMessage('Plik '+IntToStr(FFileIndex)+' został utworzony');
end;
end.
Poniżej przykład dla wyświetlania w Label1 informacji po wykonaniu instrukcji:
unit Unit1;
{$mode objfpc}{$H+}
{$define UseCThreads}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Unix;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
{ Watek1 }
Watek1 = class(TThread)
private
fStatusText : string;
procedure ShowStatus;
protected
procedure Execute; override;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
Instrukcja1 : Watek1;
begin
Instrukcja1 := Watek1.Create(False);
end;
procedure Watek1.ShowStatus;
begin
Form1.Label1.Caption := fStatusText;
end;
procedure Watek1.Execute;
begin
fpsystem('xterm');
//
fStatusText := 'Instrukcja 1 zakończona';
Synchronize(@Showstatus);
//
fpsystem('xterm');
//
fStatusText := 'Instrukcja 2 zakończona';
Synchronize(@Showstatus);
end;
end.
Temat uważam za zamknięty. Dziękuję wszystkim za poświęcony czas :)