Re: FindComponent

Posted by Dan on March 23, 2006

In Reply to FindComponent posted by Andrew on March 12, 2006

: I've got a tcheckbox component named MyCheckBox1. During runtime, the program goes through a procedure with 1 line something like:
: If TCheckBox( FindComponent( 'MyCheckBox1' ) ).Checked Then...
: but i'm getting an access violation.

I've tried the code below 5 minutes ago in Delphi 4 as well as Delphi 7, and it works without errors:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if TCheckBox(FindComponent('CheckBox1')).Checked then
    ShowMessage('True')
  else
    ShowMessage('False');
end;

I suggest you copy this and try it, just to check if your problem is not just a typing error. Of course, firstly add a Button1 and a CheckBox1 to your form :)

Related Articles and Replies