[Lazarus] Foreach?
Martin
lazarus at mfriebe.de
Sat Jun 8 10:20:35 CEST 2013
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....
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.
--------------
As for the debugger crash, could you reproduce it And produce a log?
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session
More information about the Lazarus
mailing list