?
Solved

Break on variable change

Posted on 2001-07-31
10
Medium Priority
?
1,166 Views
Last Modified: 2012-05-04
I am using Delphi 1, and I want to know if I can set a breakpoint using debug, but only break when a variable changes?

i.e.

I set a watch on VarName and I want the program to beak everytime the value of VarName changes.
0
Comment
Question by:Brenda-Leigh
10 Comments
 
LVL 4

Expert Comment

by:YodaMage
ID: 6338598
I cheat when doing this. Use a test function like this and it'l do what you want:

procedure TestVarandBreak(VarName : Integer);
var
  value2 : Integer;
begin
  if (VarName <> value2) then
  begin
    Showmessage(inttostr(Val2) + ' changed to ' +
     inttostr(VarName));
    Val2 := VarName;
  end;
end;

Then call this in your loop or when you assign Varname.

 
 
0
 

Expert Comment

by:Yevgen
ID: 6338774
Who's using Delphi 1??? Isnt it a little bit old???
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6339455
Yevgen in some places Windows 3.1 is still used !!!!!. Funny, strange but real.
ziolko.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Brenda-Leigh
ID: 6340008
Geez, didn't anybody ever hear of maintenance of legacy software?
Aside from that
The application is extremely large, and in the DLL that I want to capture my variable there nearly 100 procedures, so calling the showmessage isn't really practical. But thanks for the idea.
0
 
LVL 3

Expert Comment

by:raidos
ID: 6340501
If you set up a dummy Class that looks something like this.

  TDummyClass = Class
    fVariable : Integer;
  private
    Procedure SetVariable(Value: Integer);
    Function GetVariable: Integer;
  public
    Property YourVarName: Integer Read GetVariable write SetVariable;
  End;

Procedure TDummyClass.SetVariable(Value: Integer);
Begin
  If Value <> fVariable Then
    fVariable := Value; //BreakPoint here
End;

Function TDummyClass.GetVariable: Integer;
Begin
  Result := fVariable;
End;

  Then you will need a global variable for you class. which will need to be created when you initialize the dll, and freed when you close the dll.
  DummyVar : TDummyClass;

  At init, do
  DummyVar := TDummyClass.Create;
 
  At deinit do
  DummyVar.Free;

Then replace every call to set your variable with
  DummyVar.YourVarName := YourNewValue;
 
Atleast thats how i would do it

//raidos
{Code actually tested in D1}
so it should work..=))
0
 

Author Comment

by:Brenda-Leigh
ID: 6341568
Obviously you went to quite a bit of trouble, so thank you very much. I am not sure though that I see the difference in what you suggest and just putting a break point everywhere I call the variable. Which is what I eventually succumbed to(43 breakpoints!). I was hoping that there was some inherent utility in Delphi's Debug that would allow you to do that, after all VB, C++, and even RPG will let you specifiy a condition to break on. Then rather than watching the variable go through all its hoops and loops where the value is not changed, I could just see the call stack when the value actually changes.
0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6341947
breakpoint conditions are available in Delphi 5... But I know that is useless to you at this point.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 8730060
Is this Q still open?
ziolko.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8735036
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To be PAQ/Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0
 

Accepted Solution

by:
RotaredoM earned 0 total points
ID: 8822631
Finalized as recommended.

Question PAQed and 50 points refunded.

RotaredoM
CS Mod @ EE
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question