Sonra TThreadDeneme.Destroy içine TTankNesnesi.Free yaptım, hata verdi, TTanknesnesi.destroy yaptım, hata verdi. Yapamadım, hatam nedir acaba? Yardımcı olursanız sevinirim... Yazdığım Kodlar şunlar;
Kod: Tümünü seç
unit UTankNesnesi;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,stdctrls;
type
TTank=Class(TEdit)
private
FXKoordinati,FYKoordinati:integer;
procedure WXKoordinati(const Value: integer);
procedure WYKoordinati(const Value: integer);
public
property XKoordinati:integer read FXKoordinati write WXKoordinati;
property YKoordinati:integer read FYKoordinati write WYKoordinati;
constructor Create(AOwner:TWinControl;x,y:integer);
destructor destroy;override;
end;
implementation
{ TTank }
{ TTank }
{ TTank }
{ TTank }
{ TTank }
constructor TTank.Create(AOwner: TWinControl; x, y: integer);
begin
inherited create(AOwner);
Parent:=AOwner;
FXKoordinati:=x; Left:=FXKoordinati;
FYKoordinati:=y; Top:=FYKoordinati;
end;
destructor TTank.destroy;
begin
inherited destroy;
end;
procedure TTank.WXKoordinati(const Value: integer);
begin
FXKoordinati := Value;
Left:=FXKoordinati;
end;
procedure TTank.WYKoordinati(const Value: integer);
begin
FYKoordinati := Value;
Top:=FYKoordinati;
end;
end.
Kod: Tümünü seç
unit UThread;
interface
uses
Classes,Controls,UTankNesnesi;
type
TThreadDeneme = class(TThread)
private
MyEdit:TTank;
FOwner:TWinControl;
procedure EsasProsedur;
{ Private declarations }
public
constructor create(AOwner:TWinControl;x,y:integer);
destructor destroy;override;
protected
procedure Execute; override;
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TThreadDeneme.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TThreadDeneme }
constructor TThreadDeneme.create(AOwner: TWinControl; x, y: integer);
begin
inherited create(false);
FOwner:=AOwner;
MyEdit:=TTank.Create(AOwner,x,y);
FreeOnTerminate:=true;
end;
destructor TThreadDeneme.destroy;
begin
MyEdit.destroy;
inherited destroy;
end;
procedure TThreadDeneme.EsasProsedur;
begin
MyEdit.XKoordinati:=MyEdit.XKoordinati+1;
end;
procedure TThreadDeneme.Execute;
begin
while (not terminated) do
begin
Synchronize(EsasProsedur);
if (MyEdit.XKoordinati+MyEdit.Width)>=FOwner.ClientWidth then
exit;
end;
{ Place thread code here }
end;
end.
Kod: Tümünü seç
unit UAnaUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,UThread;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Editim:TThreadDeneme;
begin
Editim:=TThreadDeneme.create(application.MainForm,100,100);
Editim.Priority:=tpLowest;
end;
end.