delphi - Iterating a panels controls results in an index out of bounds error. Why? -
i using delphi 7 (yes, hear guffaws). have tabbed notebook want controls appear in sequence prior control finished correctly. each page in notebook, have named sheet. , controls on sheet, use tag property determine whether visible @ each step. steps result in 1 new control showing, steps have many 5 controls popping view. thought iterate through controls on tab sheet that's in view , turn off tag greater current step value. on page in question, there appear 23 controls in all, labels in view, edit fields pop view , arrow-shaped buttons advancing when newly popped field gets changed. seemed simple enough, except kept generating index out of range errors. sequence shut down out detailed error message eurekalog, not opened should have been. 'resolved' issue plugging in check name of control knew last in list , quitting loop @ point. added test kounter.tag <> 0 avoid leaving submit , cancel buttons on in routes. ideas why kounter kept on past 23?
procedure tfrmmain.viztogglewtp; var kounter: integer; kontrol: tcontrol; kontrolz: integer; begin kontrolz := sheetprintouts.controlcount; kounter := 1 kontrolz begin // avoid index error, check cancel button , exit @ point if sheetprintouts.controls[kounter].name = 'btncancelwtp' break; if (sheetprintouts.controls[kounter]) tnxedit begin kontrol := tnxedit(sheetprintouts.controls[kounter]); kontrol.visible := (kontrol.tag <= wtpstep); end; if (sheetprintouts.controls[kounter]) tjvshapedbutton begin kontrol := tjvshapedbutton(sheetprintouts.controls[kounter]); kontrol.visible := ((kontrol.tag <= wtpstep) , (kontrol.tag <> 0)); end; end; end;
you need replace
for kounter := 1 kontrolz
with
for kounter := 0 kontrolz-1
since controls
array zero-based.
for instance, if there 3 controls, indexed 0, 1, 2
, not 1, 2, 3
.
Comments
Post a Comment