SteveHatcher 1 Posted December 6, 2022 I am trying to understand some relatively simple Delphi code for a GUI and am wondering if there is any tool which can tell me what which classes call what, and when etc. (Delphi 10.4 Community Edition.) I have looked at class explorer and Model View, but they both show just the classes (and hierarchies) which are used, not necessarily when one calls another. What I am after is something generated that would look as follows (just making this up): ObjectA ObjectA.Prop1 ObjectA.Prop1.doesSomething ObjectA.ButtonClick tmpObjectCreate tmpObjectCreate.Prop1.doesSomethingElse ObjectA.CallSomeMethod Sort of what you might get from adding a breakpoint and steeping through line by line, but wondering if there is any way to generate this automatically? This might not exist but would love some input. Thanks Share this post Link to post
chkaufmann 17 Posted December 6, 2022 You may add debug messages in your code (see OutputDebugString). Personally I wrote a wrapper arround this method and with each call I add an id. At the start of my application I set a list of ids and then only messages with these ids are sent to the event log: procedure TBSDebug.Message(const AMessage: String; ALogId: Integer); begin if FLogIds.Contains(ALogId) then OutputDebugString(PChar(AMessage)); end; Christian Share this post Link to post
dummzeuch 1505 Posted December 6, 2022 1 hour ago, SteveHatcher said: Sort of what you might get from adding a breakpoint and steeping through line by line, but wondering if there is any way to generate this automatically? This might not exist but would love some input. When I looked at the source code of the Delphi Code Coverage tool some time ago I thought that it could be used to do exactly this: Create a trace of the code execution. It doesn't do that out of the box but it should be possible to use the source code as the base for such a tool. Background: Delphi Code Coverage starts the executable as a debugger. It analyses the map file to create breakpoints for each executable line and then runs the program until it finishes. During that time it logs any callback it receives from Windows when a breakpoint is being hit. That data is later used to generate an overview of the source lines that were actually executed. If that sounds like it could be used to generate a trace, that's exactly my thought. I would love to give it a try but I doubt that I will find the time. Share this post Link to post
PeterBelow 238 Posted December 6, 2022 8 hours ago, SteveHatcher said: I am trying to understand some relatively simple Delphi code for a GUI and am wondering if there is any tool which can tell me what which classes call what, and when etc. (Delphi 10.4 Community Edition.) I have looked at class explorer and Model View, but they both show just the classes (and hierarchies) which are used, not necessarily when one calls another. What I am after is something generated that would look as follows (just making this up): ObjectA ObjectA.Prop1 ObjectA.Prop1.doesSomething ObjectA.ButtonClick tmpObjectCreate tmpObjectCreate.Prop1.doesSomethingElse ObjectA.CallSomeMethod Sort of what you might get from adding a breakpoint and steeping through line by line, but wondering if there is any way to generate this automatically? This might not exist but would love some input. Thanks Pascal Analyzer may be helpful in this context. It is not free but if I remember correctly you can evaluate it for a period until paying for it. Have not used it myself, though. Share this post Link to post
Pat Foley 51 Posted December 6, 2022 10 hours ago, SteveHatcher said: ObjectA ObjectA.Prop1 ObjectA.Prop1.doesSomething ObjectA.ButtonClick tmpObjectCreate tmpObjectCreate.Prop1.doesSomethingElse ObjectA.CallSomeMethod That kind of looks like DFM source. If you start in debug layout the Stack Trace and local variables on left slide outs could looked at breakpoints set. The VCL uses component streaming to build the IDE design window these components are streamed into the compiler to make an executable. The following example would be pasted on a form. Click on Button1 and assign a click event. compile the program. Copy all the text in memo and paste onto form in IDE design. Stop the exe and recompile. Try the Hello button it will be hooked to your button1click. Note may to remove margin=4 on older D Another feature is using control key down and mousedown on TForm will drill down to TObject. object Panel1: TPanel Left = 380 Top = 70 Width = 371 Height = 341 Margins.Left = 4 Margins.Top = 4 Margins.Right = 4 Margins.Bottom = 4 Caption = 'Panel1' TabOrder = 0 object Button1: TButton Left = 140 Top = 250 Width = 94 Height = 31 Margins.Left = 4 Margins.Top = 4 Margins.Right = 4 Margins.Bottom = 4 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end object Memo1: TMemo Left = 90 Top = 20 Width = 231 Height = 111 Margins.Left = 4 Margins.Top = 4 Margins.Right = 4 Margins.Bottom = 4 Lines.Strings = ( 'object btn5000: TButton' ' Left = 140' ' Top = 250' ' Width = 94' ' Height = 31' ' Margins.Left = 4' ' Margins.Top = 4' ' Margins.Right = 4' ' Margins.Bottom = 4' ' Caption = '#39'Hello'#39 ' TabOrder = 0' ' OnClick = Button1Click' 'end') TabOrder = 1 end end Share this post Link to post
SteveHatcher 1 Posted December 7, 2022 Thanks everyone for your advice and input. Pascal Analyzer (actually Pascal Browser) seems the closest automated system to what I'm after. It generates a html report and shows Module Calls and Module Called-By. Definitely helping me understand the flow of the code. 1 Share this post Link to post
Uwe Raabe 2057 Posted December 7, 2022 There is also Undertand from SciTools, although a bit pricy. Share this post Link to post