Abaksoft Posted July 20, 2015 Share Posted July 20, 2015 About DCallBack (wich never stop thread). Here is a portion of code (in attachement) : procedure TMainForm.UniButton1Click(Sender: TObject); begin Obj_Animal:=TAnimal.Create; try // init Obj_Animal.Name:='Name 0'; Obj_Animal.Weight:=0; // Test1 if (1=1) then begin mes:=' Change 1 ?'; MessageDlg(mes, mtConfirmation, mbYesNo,DCallBack1); end // Test2 else if (2=2) then begin mes:=' Change 2 ?'; MessageDlg(mes, mtConfirmation, mbYesNo,DCallBack2); end; finally Obj_Animal.Free; end; // showmessage('free'); end; Question : - First problem : Why Test2 is never executed ? - Second problem : as i use oriented object methode, i have to free my Object instance at the end. the big problem is that DCallBack never Stop the thread, so, my Obj_Animal is Free before it show Dialog. (sometime it raise an exception, somtimes no !?). I didn't find a way to write this simple code !? Anyone has an idea ? thx... DCallBack.zip Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted July 20, 2015 Administrators Share Posted July 20, 2015 Create Obj_Animal in FormCreate event and Free it in FormDestroy. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 20, 2015 Author Share Posted July 20, 2015 Thx Farshad, I find finally a way : Puting the next Test2 in DCallBack1 it's a little disturbing in terms of development method but get used to it. procedure TMainForm.DCallBack1(Sender: TComponent; Res: Integer); begin if Res=mrYes then begin Obj_Animal.Name:='Name 1'; Obj_Animal.Weight :=100; Display; end; if (2=2) then begin mes:=' Change 2 ?'; MessageDlg(mes, mtConfirmation, mbYesNo,DCallBack2); end; end; procedure TMainForm.UniButton1Click(Sender: TObject); begin Obj_Animal:=TAnimal.Create; try // init Obj_Animal.Name:='Name 0'; Obj_Animal.Weight:=0; // Test1 if (1=1) then begin mes:=' Change 1 ?'; MessageDlg(mes, mtConfirmation, mbYesNo,DCallBack1); end; finally // Obj_Animal.Free; end; // showmessage('free'); end; And with your suggestion, all is OK. Thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.