thread yok olurken system error. Code: 5 hatası veriyor...

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kilitli
Kullanıcı avatarı
huseyinkucuk
Üye
Mesajlar: 142
Kayıt: 29 Nis 2005 10:03
Konum: İstanbul
İletişim:

thread yok olurken system error. Code: 5 hatası veriyor...

Mesaj gönderen huseyinkucuk »

Arkadaşlar... TEditi ata sınıf alan TTank diye bi sınıf yaptım... (pek bi özellik eklemedim, aslında hiç bi özellik eklemedim desem yeri var) Sonra TThreadDeneme diye bi Thread sınıfı tanımladım... Bu TThreadDeneme sınıfının içinde (aşağıdaki kodda da göreceğiniz gibi) yaptığım sınıftan bir nesne tanımladım, bu nesne sürekli sağa doğru gidiyor ve formun sonuna geldiği zaman yok olması gerekiyor... Ben düşümdüm ki; TTank nesnesini TThreadDeneme nesnesinin private bölümünde tanımladığıma göre TThreadDeneme nesnesi yok olunca TTank nesnesi de yok olur diye düşündüm... Ama olmadı, formun en sağında durdu öylecene TTank'tan türetilmiş nesne(ler).
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.
29.04.2005 tarihi itibariyle Delphi öğrenmeye başlayan yeni bir kullanıcı sayılabilirim.
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Soruyu yeni başlık açarak tekrar tekrar sormayın önceki başlığınızdan devam edin :!:
Kilitli