I create dynamically 5 checkboxes, which should be later linked to HTML elements. I want to change the checked property of some of them, when clicking on the first one.
I think the Checkboxes have to be create by TWebCheckBox.Create('Cb' + inttostr(i)) if I want a link to the HTML elements. But in that case, I can't use GetElementById in the right way.
TWebCheckBox.Create(Self) is working well with FindComponent, but in that case, the link to the HTML elements is not done.
What am I doing wrong?
procedure TForm2.WebButton2Click(Sender: TObject);
var
cb: TWebCheckBox;
i: integer;
begin
for i := 1 to 5 do
begin
// cb := TWebCheckBox.Create(Self);
cb := TWebCheckBox.Create('Cb' + inttostr(i));
cb.Name := 'Cb' + inttostr(i);
cb.ElementID := 'Cb' + inttostr(i);
cb.Tag := i;
cb.Parent := Self;
cb.Top := 50 + 30 * i;
cb.OnClick := CbClick;
end;
end;
procedure TForm2.CbClick(Sender: TObject);
begin
if (Sender as TWebCheckBox).Tag = 1 then
begin
asm
document.getElementById('Cb3').checked=true;
end;
// Error if created with TWebCheckBox.Create(Self), and doesn't work with TWebCheckBox.Create('Cb' + inttostr(i));
// TWebCheckBox(FindComponent('Cb4')).checked := true;
// FindComponent returns nil if created with TWebCheckBox.Create('Cb' + inttostr(i));
document.getElementById('Cb5').setAttribute('checked', 'true');
// Error if created with TWebCheckBox.Create(Self), and doesn't work with TWebCheckBox.Create('Cb' + inttostr(i));
end;
end;
`