Jump to content

Houston...We have a problem !


Abaksoft

Recommended Posts

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 !?   :wacko:
Anyone has an idea ?
 
thx...
 

 

DCallBack.zip

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...