Registriert seit: 21. Mai 2014
44 Beiträge
|
AW: Threads und TBitmaps
3. Sep 2014, 15:55
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, UThread;
type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Paintthread : TPaintThread;
i : Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Paintthread := TPaintThread.create(false);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(i);
Paintthread.zeichnen;
end;
end.
Delphi-Quellcode:
unit UThread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;
type
Image = TImage;
TPaintThread = class(TThread)
private
Zeichenflaeche: TImage;
Original, MyBild : TBitmap;
i : integer;
protected
procedure Execute; override;
public
procedure zeichnen;
constructor Create(CreateSuspended: Boolean);
end;
implementation
constructor TPaintThread.Create(CreateSuspended: Boolean);
begin
inherited;
end;
procedure TPaintThread.Execute;
begin
While (Terminated = False) do
begin
Synchronize(Zeichnen);
sleep(1);
end;
end;
procedure TPaintThread.Zeichnen;
begin
inc(i);
end;
end.
Delphi-Quellcode:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
UThread in 'UThread.pas';
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
|
|
Zitat
|