Creating custom controls. Do I have to give them a name?












0















Let's say I create (from TPanel) and install my own control. It contains only one button:



constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited Create(aOwner);

btn:= TButton.Create(Self);
btn.Parent:= Self;
btn.Name:= 'xxx'; <-------- mandatory?
end;


Is it mandatory to give a name to that panel?





This question started from a comment posted by dummzeuch here:




This happens when your label doesn't have a name. The IDE adds
declarations to the class only if the control has got a name (how else
should it declare it?).




What does a EClassNotFound raised at runtime really mean when the class in question is there at compile and link time, and there explicitly in code?



(I am specifically refer to that comment only)










share|improve this question




















  • 1





    You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

    – Dalija Prasnikar
    Nov 13 '18 at 10:30






  • 1





    The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

    – Dsm
    Nov 13 '18 at 10:56











  • @DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

    – Rigel
    Nov 13 '18 at 11:11













  • @Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

    – Rigel
    Nov 13 '18 at 11:12








  • 1





    Comment posted as answer, as requested

    – Dsm
    Nov 13 '18 at 13:51
















0















Let's say I create (from TPanel) and install my own control. It contains only one button:



constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited Create(aOwner);

btn:= TButton.Create(Self);
btn.Parent:= Self;
btn.Name:= 'xxx'; <-------- mandatory?
end;


Is it mandatory to give a name to that panel?





This question started from a comment posted by dummzeuch here:




This happens when your label doesn't have a name. The IDE adds
declarations to the class only if the control has got a name (how else
should it declare it?).




What does a EClassNotFound raised at runtime really mean when the class in question is there at compile and link time, and there explicitly in code?



(I am specifically refer to that comment only)










share|improve this question




















  • 1





    You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

    – Dalija Prasnikar
    Nov 13 '18 at 10:30






  • 1





    The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

    – Dsm
    Nov 13 '18 at 10:56











  • @DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

    – Rigel
    Nov 13 '18 at 11:11













  • @Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

    – Rigel
    Nov 13 '18 at 11:12








  • 1





    Comment posted as answer, as requested

    – Dsm
    Nov 13 '18 at 13:51














0












0








0








Let's say I create (from TPanel) and install my own control. It contains only one button:



constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited Create(aOwner);

btn:= TButton.Create(Self);
btn.Parent:= Self;
btn.Name:= 'xxx'; <-------- mandatory?
end;


Is it mandatory to give a name to that panel?





This question started from a comment posted by dummzeuch here:




This happens when your label doesn't have a name. The IDE adds
declarations to the class only if the control has got a name (how else
should it declare it?).




What does a EClassNotFound raised at runtime really mean when the class in question is there at compile and link time, and there explicitly in code?



(I am specifically refer to that comment only)










share|improve this question
















Let's say I create (from TPanel) and install my own control. It contains only one button:



constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited Create(aOwner);

btn:= TButton.Create(Self);
btn.Parent:= Self;
btn.Name:= 'xxx'; <-------- mandatory?
end;


Is it mandatory to give a name to that panel?





This question started from a comment posted by dummzeuch here:




This happens when your label doesn't have a name. The IDE adds
declarations to the class only if the control has got a name (how else
should it declare it?).




What does a EClassNotFound raised at runtime really mean when the class in question is there at compile and link time, and there explicitly in code?



(I am specifically refer to that comment only)







delphi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:06







Rigel

















asked Nov 13 '18 at 10:13









RigelRigel

9,96514111223




9,96514111223








  • 1





    You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

    – Dalija Prasnikar
    Nov 13 '18 at 10:30






  • 1





    The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

    – Dsm
    Nov 13 '18 at 10:56











  • @DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

    – Rigel
    Nov 13 '18 at 11:11













  • @Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

    – Rigel
    Nov 13 '18 at 11:12








  • 1





    Comment posted as answer, as requested

    – Dsm
    Nov 13 '18 at 13:51














  • 1





    You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

    – Dalija Prasnikar
    Nov 13 '18 at 10:30






  • 1





    The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

    – Dsm
    Nov 13 '18 at 10:56











  • @DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

    – Rigel
    Nov 13 '18 at 11:11













  • @Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

    – Rigel
    Nov 13 '18 at 11:12








  • 1





    Comment posted as answer, as requested

    – Dsm
    Nov 13 '18 at 13:51








1




1





You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

– Dalija Prasnikar
Nov 13 '18 at 10:30





You are mixing apples and oranges. Linked question was about streaming from dfm, and here you are creating control in code. No, you don't need a name, but you might want to set it as sub component.

– Dalija Prasnikar
Nov 13 '18 at 10:30




1




1





The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

– Dsm
Nov 13 '18 at 10:56





The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.

– Dsm
Nov 13 '18 at 10:56













@DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

– Rigel
Nov 13 '18 at 11:11







@DalijaPrasnikar - Nope. I was not speaking about that question. I was speaking about one VERY specific comment (that was also not answering that question).

– Rigel
Nov 13 '18 at 11:11















@Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

– Rigel
Nov 13 '18 at 11:12







@Dsm - thanks. I was not naming my sub-controls. And as you said, it was working ok. But that comment got me worrying: "what if I was doing it wrong all the time" ? If you post this as answer, I will accept it.

– Rigel
Nov 13 '18 at 11:12






1




1





Comment posted as answer, as requested

– Dsm
Nov 13 '18 at 13:51





Comment posted as answer, as requested

– Dsm
Nov 13 '18 at 13:51












2 Answers
2






active

oldest

votes


















3














No, you do not need to name sub components.



However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:



constructor TMyPanel.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
btn := TButton.Create(Self);
btn.Parent := Self;
btn.SetSubComponent(True); // <-- ADD THIS
end;





share|improve this answer
























  • "SetSubComponent" - oh... yeah!

    – Rigel
    Nov 15 '18 at 9:27



















2














The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278644%2fcreating-custom-controls-do-i-have-to-give-them-a-name%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    No, you do not need to name sub components.



    However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:



    constructor TMyPanel.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    btn := TButton.Create(Self);
    btn.Parent := Self;
    btn.SetSubComponent(True); // <-- ADD THIS
    end;





    share|improve this answer
























    • "SetSubComponent" - oh... yeah!

      – Rigel
      Nov 15 '18 at 9:27
















    3














    No, you do not need to name sub components.



    However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:



    constructor TMyPanel.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    btn := TButton.Create(Self);
    btn.Parent := Self;
    btn.SetSubComponent(True); // <-- ADD THIS
    end;





    share|improve this answer
























    • "SetSubComponent" - oh... yeah!

      – Rigel
      Nov 15 '18 at 9:27














    3












    3








    3







    No, you do not need to name sub components.



    However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:



    constructor TMyPanel.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    btn := TButton.Create(Self);
    btn.Parent := Self;
    btn.SetSubComponent(True); // <-- ADD THIS
    end;





    share|improve this answer













    No, you do not need to name sub components.



    However, if you intent on exposing access to a sub componenet as a property that gets streamed in a DFM, you do need to mark the sub component, at least:



    constructor TMyPanel.Create(aOwner: TComponent);
    begin
    inherited Create(aOwner);
    btn := TButton.Create(Self);
    btn.Parent := Self;
    btn.SetSubComponent(True); // <-- ADD THIS
    end;






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 17:09









    Remy LebeauRemy Lebeau

    333k18251446




    333k18251446













    • "SetSubComponent" - oh... yeah!

      – Rigel
      Nov 15 '18 at 9:27



















    • "SetSubComponent" - oh... yeah!

      – Rigel
      Nov 15 '18 at 9:27

















    "SetSubComponent" - oh... yeah!

    – Rigel
    Nov 15 '18 at 9:27





    "SetSubComponent" - oh... yeah!

    – Rigel
    Nov 15 '18 at 9:27













    2














    The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.






    share|improve this answer




























      2














      The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.






      share|improve this answer


























        2












        2








        2







        The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.






        share|improve this answer













        The IDE needs components to have a name, but otherwise no. So if the IDE does not directly access any of the properties of the subcomponent then it does not need a name. This does not stop the properties of the component being set by the parent, for example via a property of the parent that is visible to the IDE.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 13:47









        DsmDsm

        5,1281320




        5,1281320






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278644%2fcreating-custom-controls-do-i-have-to-give-them-a-name%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values