In your first example--if you're going that route--please, don't reference a particular instance from inside the class!
Your constructor, for example, should look like this:
constructor TMainForm.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Button:=TButton.Create(Form);
with Button do
begin
Parent := Self; {*NOT* Parent := form}
Caption:='Press';
Left:=50;
Top:=50;
Width:=80;
Height:=30;
OnClick := @ButtonOnClick; {*NOT* @Form.ButtonOnClick;}
end;
end;
Otherwise,
only that particular object instance will work, not any other that may be created dynamically; i.e. if someone clicks the button in say
AnotherForm, it will act as if the button in
Form had been clicked. Which, I assume, is not what you want, is it?