Recent

Author Topic: problem looping through checkboxes  (Read 2604 times)

acp693

  • Jr. Member
  • **
  • Posts: 73
problem looping through checkboxes
« on: March 10, 2013, 08:01:06 pm »
Hi,

I'm using the following code to loop through 4 checkboxes situated in groupbox7. However the compiler won't let me do: 

if (chk.checked ) then begin

Anybody got an idea?

Many thanks

Albert



Code: [Select]
var
  chk: Tcontrol;
  k:integer; 

for k:= 0 to (unit2.Form2.GroupBox7.ControlCount -1)  do begin
     if unit2.Form2.GroupBox7.Controls[k]   is Tcheckbox  then begin;
           chk:= unit2.Form2.GroupBox7.Controls[k];
           if (chk.checked ) then begin      // <---------   here's the problem line
                do stuff etc.
           end;
     end;
end;     


Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: problem looping through checkboxes
« Reply #1 on: March 10, 2013, 08:07:54 pm »
Replace
Code: [Select]
if (chk.checked ) then begin      // <---------   here's the problem linewith
Code: [Select]
if (chk as TCheckBox).checked then begin Or declare "chk: TCheckBox;" if you don't need it elsewhere.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

acp693

  • Jr. Member
  • **
  • Posts: 73
Re: problem looping through checkboxes
« Reply #2 on: March 10, 2013, 08:12:42 pm »
Thank you very much, I'll try it.

Best regards

Albert

 

TinyPortal © 2005-2018