'Retrieving the number of breaks in a FLowLayout
I want to programatically retrieve the number of breaks/newlines in a TFlowLayout.
I have a simple TFlowLayout with 4 regular controls inside (The TFlowLayout does not contain any TFlowLayoutBreak controls).
Depending on the width of the layout it looks like:
// * = control
// Scenario #1: No breaks
* * * *
// Scenario #2: 1 break
* * *
*
// Scenario #3: 2 breaks
* *
* *
// Scenario #4: 3 breaks
*
*
*
*
Is it possible to retrieve the number of breaks of a TFlowLayout programatically or can I only go off the width of the layout to determine the number of breaks?
Solution 1:[1]
Counting the changes in Y values for the controls looks to work since the array is in layout order.
procedure TForm1.Button1Click(Sender: TObject);
var
Cnt, I : integer;
begin
if FlowLayout1.ControlsCount = 0 then Cnt := 0 else Cnt := 1;
for I := 1 to FlowLayout1.ControlsCount - 1 do
if FlowLayout1.Controls[I-1].Position.Y <> FlowLayout1.Controls[I].Position.Y then inc(cnt);
button1.Text := IntToStr(Cnt);
end;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian |
