14 Ekim 2020 Çarşamba tarihinde saat 02:49:03 UTC+3 itibarıyla
alexandre...@gmail.com şunları yazdı:
You can extend Tthread to your own thread and set a property named ownerForm: TForm or any object you want.and can set when create your own thread.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.IOUtils, System.Types;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread= class(TThread)
private
FOwnerForm: TForm;
protected
public
constructor Create(ownerForm: TForm);
destructor Destroy; override;
procedure Execute(); override;
published
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyThread }
constructor TMyThread.Create(ownerForm: TForm);
begin
inherited Create;
FOwnerForm:= ownerForm;
Self.FreeOnTerminate := True;
end;
destructor TMyThread.Destroy;
begin
inherited;
end;
procedure TMyThread.Execute;
begin
try
fownerForm.buttonX.Click();
except on E: Exception do
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var MT: TMyThread;
begin
MT := TMyThread.Create(Self);
end;
end.