Solved

Break on variable change

Posted on 2001-07-31
10
1,039 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
Comment Utility
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
Comment Utility
Who's using Delphi 1??? Isnt it a little bit old???
0
 
LVL 21

Expert Comment

by:ziolko
Comment Utility
Yevgen in some places Windows 3.1 is still used !!!!!. Funny, strange but real.
ziolko.
0
 

Author Comment

by:Brenda-Leigh
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Brenda-Leigh
Comment Utility
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
Comment Utility
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
Comment Utility
Is this Q still open?
ziolko.
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility
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
Comment Utility
Finalized as recommended.

Question PAQed and 50 points refunded.

RotaredoM
CS Mod @ EE
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now