Ersun
03-18-2008, 06:57 PM
Design Time Çalışan Nesne
Tasarım Zamanında Çalışan Bir nesne. Boş bir unit açın. type dan sonrasına aşağıdaki kodu copy paste yapın ve componenti kurun. Daha sonra komponenti forma yerleştirin ve sonucu gözlemleyin. Normalde sabit olan tasarım formunuzu hareketli göreceksiniz.Hiç böyle bir nesne gördünüz mü bilmiyorum. Enterasan ama bu nesne Design Time sırasında çalışıyor. Aşağıdaki kodları boş bir unit açarak kopyala yapıştır yapın ve kaydedin. Daha sonra Component > Install Component diyerek bu nesneyi kurun. Standard sekmesine bu nesne gelecektir. Daha sonra bir forma bu nesneyi atın. Sonucu izleyin.
type
TMyThread = class(TThread)
private
FOwner: TForm;
procedure Process;
public
constructor Create(AOwner: TForm);
destructor Destroy; override;
procedure Execute; override;
end;
TMyObj = class(TGraphicControl)
private
FThreadObj: TMyThread;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TMyObj]);
end;
{ TMyThread }
constructor TMyThread.Create(AOwner: TForm);
begin
FOwner := AOwner;
inherited Create(False);
end;
destructor TMyThread.Destroy;
begin
inherited;
end;
procedure TMyThread.Execute;
begin
while not Self.Terminated do
begin
Synchronize(Self.Process);
Sleep(100);
end;
end;
procedure TMyThread.Process;
begin
FOwner.Left := Random(200);
FOwner.Top := Random(200);
end;
{ TMyObj }
constructor TMyObj.Create(AOwner: TComponent);
begin
inherited;
FThreadObj := TMyThread.Create(TForm(AOwner));
end;
destructor TMyObj.Destroy;
begin
inherited;
end;
procedure TMyObj.Paint;
begin
inherited;
end;
Tasarım Zamanında Çalışan Bir nesne. Boş bir unit açın. type dan sonrasına aşağıdaki kodu copy paste yapın ve componenti kurun. Daha sonra komponenti forma yerleştirin ve sonucu gözlemleyin. Normalde sabit olan tasarım formunuzu hareketli göreceksiniz.Hiç böyle bir nesne gördünüz mü bilmiyorum. Enterasan ama bu nesne Design Time sırasında çalışıyor. Aşağıdaki kodları boş bir unit açarak kopyala yapıştır yapın ve kaydedin. Daha sonra Component > Install Component diyerek bu nesneyi kurun. Standard sekmesine bu nesne gelecektir. Daha sonra bir forma bu nesneyi atın. Sonucu izleyin.
type
TMyThread = class(TThread)
private
FOwner: TForm;
procedure Process;
public
constructor Create(AOwner: TForm);
destructor Destroy; override;
procedure Execute; override;
end;
TMyObj = class(TGraphicControl)
private
FThreadObj: TMyThread;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TMyObj]);
end;
{ TMyThread }
constructor TMyThread.Create(AOwner: TForm);
begin
FOwner := AOwner;
inherited Create(False);
end;
destructor TMyThread.Destroy;
begin
inherited;
end;
procedure TMyThread.Execute;
begin
while not Self.Terminated do
begin
Synchronize(Self.Process);
Sleep(100);
end;
end;
procedure TMyThread.Process;
begin
FOwner.Left := Random(200);
FOwner.Top := Random(200);
end;
{ TMyObj }
constructor TMyObj.Create(AOwner: TComponent);
begin
inherited;
FThreadObj := TMyThread.Create(TForm(AOwner));
end;
destructor TMyObj.Destroy;
begin
inherited;
end;
procedure TMyObj.Paint;
begin
inherited;
end;