Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle subcomponents and properties created in runtime vs designtime?
    text
    copied!<p>I can' t realize this thing. I have a component in DELPHI that includes 2 other components: a Firemonkey Layout and inside of that an dynamic array of TLayout which includes a TRectangle. This is achieved through the property BarNumber.</p> <p>I have lots of problems about Design Time vs. Runtime behaviour, this is due to the DFM (FMX in Firemonkey) that stores the subcomponents as part of the Object. Now. This is the code of the On Create part.</p> <pre><code>constructor TFluffyTable.Create(Owner: TComponent); var i: integer; begin inherited Create(Owner); Width:=300; Height:= 160; BarNumber:=100; SetLength(Column, FBarNumber); for i := 0 to (FBarNumber-1) do begin Column[i]:= TColumn.Create(Self); Column[i].Name:= 'Column_' + IntToStr(i); Column[i].Parent:= Self; Column[i].Height:=Height; Column[i].Width:=Width/FBarNumber; Column[i].Align:= TAlignLayout.alMostLeft; end; end; </code></pre> <p>If I register the component and I use it in design time I get the correct number of bars displayed. But if I run the program with the component, I get twice the number of bars, since the EXE loads the values. I managed to solve this with </p> <pre><code> if not (csDesigning in ComponentState) then </code></pre> <p>just before the for loop. But I can't see, obviously, the BARS in design mode. Well I can stand that if this is the only solution. That's not over..! For a strange reason, The only one place I can set my values for Width, Height and BarNumber is that part of code. If I set them in the object inspector they won't be considered and reset to default when I run the program. (BarNumber is a variable which reads and writes on FBarNumber)</p> <p>In short: I don't know how to handle and manage my component to make BarNumber and other properties to be set in design time, and to see the correct number of bars in Runtime. Thank you so much.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload