Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Storing variables in components with a loop.

Hi,

I have several checkboxes (Checkbox0, Checkbox1, ...) and a binary string (1011).
I want to inspect the string and depending check the corresponding checkboxes.

var
  i: integer
  f, binary: string
For i=0 to 4 do begin
  f := 'Checkbox' + inttostr(i);
  if binary[i] = '1' then
     f.checked := true
  else
    f.checked := false;
End;

Of course this gives errors as f is just a string.
How can i tell my program to that f should be handles as the name of the checkbox ??

Regards,
Marnik
0
marnik
Asked:
marnik
  • 2
1 Solution
 
kretzschmarCommented:
var
  i: integer
  f : TCheckBox;
  binary: string
begin
  For i=1 to 4 do
  begin
    f := findcomponent('Checkbox' + inttostr(i)) as TCheckBox;
    if assigned(f) then
      if binary[i] = '1' then
         f.checked := true
      else
        f.checked := false;
  End;
end:

just from head

meikl ;-)
0
 
kretzschmarCommented:
btw.

this can be shortened:

      if binary[i] = '1' then
         f.checked := true
      else
        f.checked := false;

into

f.checked := binary[i] = '1';

meikl ;-)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now