Hab' jetzt folgenden Code.
Ist der "sicher", oder ist's nur ne Frage der Zeit, bis er kracht ???
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TPainter =
class(TThread)
private
protected
procedure Execute;
override;
procedure VCL_Create;
procedure VCL_Free;
end;
var
Form1: TForm1;
Painter: TPainter;
Bitmap: TImage;
implementation
{$R *.dfm}
procedure TPainter.Execute;
begin
synchronize (VCL_create);
sleep (3000);
synchronize (VCL_Free);
end;
procedure TPainter.VCL_create;
begin
Bitmap := TImage.Create(
nil);
Bitmap.Parent := Form1;
Bitmap.Left := 10;
Bitmap.Top := 10;
Bitmap.Width := 50;
Bitmap.Height := 50;
Bitmap.Canvas.Pixels[10, 10] := clRed;
end;
procedure TPainter.VCL_Free;
begin
Bitmap.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Painter := TPainter.Create(TRUE);
Painter.FreeOnTerminate := TRUE;
Painter.Resume;
end;
end.