delphitcomponent

How to access design position on non-visual Delphi components?


When designing a form in the IDE, non-visual components (eg TMainMenus, TDatamodules) can be freely placed and positioned. The position is persisted, so that on reloading the form these components appear in the correct place.

But, TComponent does not have Top or Left properties!

So, how can my code access the 'designed position' of non visual components?


Solution

  • This can be accessed at runtime, but it's sort of a hack. (Mostly because it's implemented as sort of a hack.)

    The Left and Top properties are set up as Word-size values, and the two of them are packed together into a Longint called TComponent.FDesignInfo. You can obtain its value with the DesignInfo property. Have a look at TComponent.DefineProperties to get a look into how it's used.