Delphi - How Can I Break When the ComponentCount Form Is Reduced

The code below is reproduced from the 2000 toolbar. This is part of the procedure that reads toolbar positions and dock statuses from an INI file. I call this procedure during initialization. This code below iterates over all the components of the main form (OwnerComponent) and loads the settings of any found toolbars.

for I := 0 to OwnerComponent.ComponentCount-1 do begin ToolWindow := OwnerComponent.Components[I]; // <------------------------ .... 

This iteration takes some time (seconds - there are more than 1,500 components in the form), and I get a range error at the specified point. I found that one or more elements are leaking from the main components of the form while this loop is running, so the loop eventually tries to access one of the ends of the array as soon as this happens (it would probably be better to code this as "downto" for-loop to prevent this).

In any case, I need to find out where the main form loses the component. Can someone give me any Delphi 2006 debugging tips on how to do this? I would not expect any components of the main form to be released at this point in my program.

UPDATE

I found that when I changed the default position of the dock in the toolbar during development, I accidentally placed it on a different toolbar, and not on a dock site that had a different toolbar. I fixed the problem by removing the toolbar from the toolbar that was docked and added to the dock instead. So the problem arose:

 Dock Toolbar 1 Control 1 Control 2 Toolbar 2 Control 3 Control 4 

and the fix was to arrange them this way:

 Dock Toolbar 1 Control 1 Control 2 Toolbar 2 Control 3 Control 4 

It still indicates an error in the TB2k code, although it can be assumed that it should be able to handle nested toolbars.

+4
source share
2 answers

In addition to Lieven's answer, you can also use debug dcu and set a breakpoint in TComponent.Destroy just before entering the loop.

In both cases, you will need to examine the call stack to find out where the call / change comes from.

A very interesting article on breakpoints was written by Carey Jensen: http://caryjensen.blogspot.com/2010/08/breakpoints-with-side-effects.html

+6
source

You will need to add a data breakpoint to @Self.FComponents.FCount in order to break whenever the count changes.

  • ComponentCount is a property that returns a value from GetComponentCount
  • GetComponentCount returns FComponents.Count .
  • FComponents is an instance of TList with the private variable FCount .
+3
source

All Articles