[Lazarus] Foreach?
Sven Barth
pascaldragon at googlemail.com
Sat Jun 8 12:50:08 CEST 2013
On 08.06.2013 10:20, Martin wrote:
> On 08/06/2013 08:56, Timothy Groves wrote:
>> On 13-06-08 03:49 AM, Sven Barth wrote:
>>>
>>> c := 0;
>>> for i := 0 to frmMain.ControlCount - 1 do
>>> if (frmMain.Controls[i] is TButton) and (Pos('btnMacro',
>>> frmMain.Controls[i].Name) = 1) then begin
>>> frmMain.Controls[i].Caption := MacroList[c].Name;
>>> Inc(c);
>>> end;
>> I can see how this might work. Unfortunately, it does not, and
>> attempts to debug it crash the debugger...
>
>
> There are other controls in that list (other than btnMacroX)
>
> You must ensure, that "inc(i)" is only called if it is a btnMacro.
> Otherwise it grows to big....
The "Inc(c)" is inside the if-branch that checks for the control's name.
> Also the order is not guaranteed. So inc(i) does not work. Better to
> parse the number, from the name using
> intToStr(copy(frmMain.Controls[i].Name, 8,999))
> assuming there never is anything after the number.
That would indeed be a better idea...
Regards,
Sven
More information about the Lazarus
mailing list