Re: Unable to do a repeat calculation without closing down and starting up again.


[ Delphi Forum ]

Posted by Lionel on January 23, 2004 at 04:33:51:

In Reply to: Re: Unable to do a repeat calculation without closing down and starting up again. posted by webmaster Guido on January 21, 2004 at 15:48:36:

: : I don't know if this is a memory thing or not but I have two math routines on one page with each having an event button and a clearing button, the variables are not the same in each routine and the Edit boxes are numbered different in each routine and I can clear the data entry and results out of each edit box but I am not able to do a repeat calculation without closing down and starting the application up again. I have tried zeroing out the variables before each repeat but still get no second results or I get the wrong results. I feel sure that others have run into this type proplem of problem and I would be interested in knowing how to handle it.
: ------------------

: To debug this type of problem, it's best to cut it up in smaller pieces.

: 1. Make a copy of the entire project, let's say Project2.
: In Project2, remove everything what has to do with the SECOND calculation, and check if the error still appears.

: 2. Make another copy of the entire project, let's say Project3.
: In Project3, remove everything what has to do with the FIRST calculation, and check if the error still appears.

: In other words, make the testversion of the program smaller and smaller, until you have isolated the error.

: Let me know what the results are, if possible with some example code, and I can have a closer look at it.
*************************************************
The following code is all on one form and is an example of what I am trying to convey as my problem.
***********************************************
The top part of the form has a Calculate, Clear and Close Button with two Edit Boxes and a Results display label.
***********************************************
The bottom part of the form has the same set up, a Calculate , Clear and Close Button.
***********************************************
I don't know if I am making much sense with this but I can enter a number in Edit box 1 and multiply it by another number in Edit box 2 and read the results, I can then do the same thing in the second half of the page using Edit box 3 and Edit box 4 and read the results.
************************************************
The problem: I clear the Edit boxes and try to enter new data and repeat the operation but nothing happens ? -- on occasions I get a wrong answer which makes me think I am not erasing anything with the Clear buttons and old data is getting involved in the second attemp to make a calculation. I hope this explains my code problem if not, let me know.
************************************************

procedure TForm1.Button1Click(Sender: TObject);
VAR
  Num1,
  Num2,
  ANS : Variant;
begin
  Num1:=Edit1.Text;
  Num2:=Edit2.Text;
  //-----------------
  ANS:= Num1 * Num2;
  //-------------------
  Label7.Caption:=FloatToStr(ANS);
  //-----------------
end; 
procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit1.Clear;
  Edit2.Clear;
  label7.visible:=False;
end;
procedure TForm1.Button3Click(Sender: TObject);
 VAR
   Num3, Num4, ans : Variant;
begin
  Num3:=(Edit3.Text);
  Num4:=(Edit4.Text);
  //---------------------
  ans:=Num3*Num4;
  //-------------------
  Label8.Caption:=FloatToStr(ans);
end;
    
procedure TForm1.Button4Click(Sender: TObject);
begin
  Edit3.Clear;
  Edit4.Clear;
  //-----------
  Label8.Visible:=false;
end;
    
procedure TForm1.Button6Click(Sender: TObject);
begin
  Close;
end;
    
procedure TForm1.Button5Click(Sender: TObject);
begin
  Close;
end;
    
end.

Related Articles and Replies:


[ Delphi Forum ]