Arsip: Custom Thread Error?

 
user image
more 11 years ago

ir1keren

Gw punya mslh aneh (lagi, ato gw yg ga teliti?). Gw punya class turunan dr TThread yg deklarasinya:

TAlgo=class(TThread)
  private
    FVertex:TCollectionVertex;
    FOnUpdate:TThreadProcedure;
    FTick,FDTime:Cardinal;
    FTotTime:Cardinal;
    procedure SetVertex(V:TCollectionVertex);
    procedure RecalculateTimer;
  public
    constructor Create;
    ....
Trus di-implementation, gw ksi:

constructor TAlgo.Create;
begin
  inherited Create(True);
  FTick:=0;
  FTotTime:=0;
  FDTime:=0;
  FOnUpdate:=nil;
  FreeOnTerminate:=True;
end;
mksudnya biar begitu Terminate langsung di-free. Trus gw bikin tombol yg OnClick-nya ky gini:

 if Assigned(NetHopfield) then
      Exit;
  NetHopfield:=THopfield.Create;
  NetHopfield.Vertex:=Vertices;
  NetHopfield.OnUpdate:=OnHopfieldProcess;
  NetHopfield.OnTerminate:=OnAfterHopfield;
  ...
  NetHopfield.Resume;
NetHopfield tu turunan dari class TAlgo. Nah pas tombol diklik pertama, ok, proses jalan. Tp pas tombol diklik kedua kalinya muncul error: "Thread Error: The handle is invalid(6)" Trus gw trace, pas penekanan tombol kedua if Assigned(NetHopfield), eh malah dilewati. Jadi ternyata blm benar2 free, wajar klo pas NetHopfield.Resume muncul error. Yawdah gw akalin,

constructor TAlgo.Create;
begin
  inherited Create(True);
  ...
  FreeOnTerminate:=False;
end;
Oya, properti Terminated gw deklarasi ulang jd public, biar bs kebaca di objek laen :). Trus di event OnClick, gw kasi

if Assigned(NetHopfield) then
    if NetHopfield.Terminated then
      FreeAndNil(NetHopfield)
    else
      Exit;
..
NetHopfield.Resume;
Maksudnya pas tombol ditekan ke sekian, otomatis NetHopfield di-free, n dibuat sbg objek baru gt. Nah gw coba pas penekanan tombol kedua muncul pesan error: "Access violation at address 0046ABC4..Read of address 000000" dan dilanjutin dg pesan: "System Error. Code: 5. Access is denied" Kynya ada yg aneh, kan pas penekanan tombol kesekian harusnya objeknya di-create ulang? klo di-create ulang kan harusnya alamat memori, handle-nya benar2 baru? Apa yg salah? ato gw ada yg terlewat ya dlm teknis multi-threading?
user image
more 11 years ago

ir1keren

weeksss..salah forum index niiyy.. maksudnya ke "Bedah Kasus"..Tulung dipindahin..thx..
user image
more 11 years ago

herux

klik kedua utk tujuan apa ni ? saya kok ga liat ada mulit-thread di sini ?
user image
more 11 years ago

herux

NetHopfield.waitfor dah ada blom ?
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com