Was bedeutet dieser Quelltext?



  • Hallo,

    Ich mache mich ans GUI vom Builder und auf http://www.functionx.com/ gehe ich grade eins nach dem anderen durch und stoße auf das erste Problem....

    Am Anfang des ersten Artikels steht

    After specifying the owner, you must also specify the parent of the control.
    The parent is responsible for destroying the child control when it (the parent) is destroyed.
    To specify the parent of a control, call its Parent property and assign it the name of the parent.
    Normally, the name of the parent is the same as the owner.
    This would be done as follows:
    [cpp]//---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    	TSomeControl * ctlShowMe = new TSomeControl (Mom);
    	ctlShowMe->Parent = Mom;
    }
    //---------------------------------------------------------------------------[/cpp]
    

    Also die erste Zeile im Block erstellt eine TSomeComtrol und reserviert Speicher. Was mir allerdings absolut neu ist, ist das (Mom) dahinter und in der zeile darunter. Was die zweite Zeile macht, verstehe ich auch nicht 😞

    Könnte mir das jemand vllt VERSTÄNDLICH erläutern?

    danke



  • Vorneweg: nicht das Parent-Control, sondern der Owner ist für das Zerstören/Freigeben des zugeordneten Controls verantwortlich.

    'Mom' ('Mutter', Wortspiel mit Parent/Eltern, könnte genauso Form1 oder PanelY heissen) ist der Name des Controls, das als Owner der neu zu erstellenden Instanz von ctlShowMe übergeben wird. Anschliessend wird Mom auch als Parent zugewiesen, damit ctlShowMe auf Mom gezeichnet wird.


Anmelden zum Antworten