"TForm(AOwner)=TForm.Create(AOwner)"? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

"TForm(AOwner)=TForm.Create(AOwner)"?

Hi!
in the code
[code]
constructor TOpenGL.Create(AOwner: TComponent);
var frm: Tform;
{some code}
frm:= TForm(AOwner);
{some code}
[/code]
I just made a guess that "TForm(AOwner=TForm.Create(AOwner)". Is it true? If not, what does it mean?

Thank you!

Comments

  • earth_walkerearth_walker Posts: 184Member
    There is another similar place in the code.
    [code]
    with TWinControl(Owner) do
    begin
    {some code}
    end;
    [/code]
    This call is in the definition of a method of a decendent(self defined) of TComponent.

    Is it the same thing as "TForm(AOwner)"?

    Thank you!

  • zibadianzibadian Posts: 6,349Member
    : There is another similar place in the code.
    : [code]
    : with TWinControl(Owner) do
    : begin
    : {some code}
    : end;
    : [/code]
    : This call is in the definition of a method of a decendent(self defined) of TComponent.
    :
    : Is it the same thing as "TForm(AOwner)"?
    :
    : Thank you!
    :
    :
    Check out the Owner property and the with statement in the help files. In this case the owner needs to be type-cast as a TWinControl to access some of its methods and properties.
    As for your previous question: The code is not the same as you put it, because the owner of an component is usually the form on which it is placed, while the owner of the forms itself is usually the application; and type-casting a TApplication object as a TForm will result in an error (Check the hierarchy of the TApplication and TForm objects).
    Note: you cannot type-cast the left side of an assignment.
  • earth_walkerearth_walker Posts: 184Member
    Thank you! I will check it.
Sign In or Register to comment.