How does this `if not` statement work without parentheses in a new service application?












-1















When creating a new Windows Service in Delphi, it inserts the following:



if not Application.DelayInitialize or Application.Installing then
Application.Initialize;


The author didn't bother including parentheses, so I'm trying to wrap my head around this. It translates to:



if (not Application.DelayInitialize) or Application.Installing then
Application.Initialize;


From what I understand, if both Application.DelayInitialize and Application.Installing are True, then it will go ahead and Initialize the service application. I don't understand why it would be initialized in this scenario - I'm pretty sure it shouldn't be initialized.



Can someone give me some clarification what I'm looking at here?





On a side note, I would never need to enable DelayInitialize as there's no need to be concerned with Server 2003. I would just like to understand what this code is actually meant to do the way it's written.










share|improve this question




















  • 1





    not operator has higher precedence.

    – LU RD
    Nov 28 '18 at 23:07








  • 1





    Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

    – GolezTrol
    Nov 28 '18 at 23:12













  • Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

    – MartynA
    Nov 28 '18 at 23:15













  • Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

    – LU RD
    Nov 28 '18 at 23:18











  • "... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

    – Sertac Akyuz
    Nov 28 '18 at 23:29
















-1















When creating a new Windows Service in Delphi, it inserts the following:



if not Application.DelayInitialize or Application.Installing then
Application.Initialize;


The author didn't bother including parentheses, so I'm trying to wrap my head around this. It translates to:



if (not Application.DelayInitialize) or Application.Installing then
Application.Initialize;


From what I understand, if both Application.DelayInitialize and Application.Installing are True, then it will go ahead and Initialize the service application. I don't understand why it would be initialized in this scenario - I'm pretty sure it shouldn't be initialized.



Can someone give me some clarification what I'm looking at here?





On a side note, I would never need to enable DelayInitialize as there's no need to be concerned with Server 2003. I would just like to understand what this code is actually meant to do the way it's written.










share|improve this question




















  • 1





    not operator has higher precedence.

    – LU RD
    Nov 28 '18 at 23:07








  • 1





    Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

    – GolezTrol
    Nov 28 '18 at 23:12













  • Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

    – MartynA
    Nov 28 '18 at 23:15













  • Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

    – LU RD
    Nov 28 '18 at 23:18











  • "... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

    – Sertac Akyuz
    Nov 28 '18 at 23:29














-1












-1








-1








When creating a new Windows Service in Delphi, it inserts the following:



if not Application.DelayInitialize or Application.Installing then
Application.Initialize;


The author didn't bother including parentheses, so I'm trying to wrap my head around this. It translates to:



if (not Application.DelayInitialize) or Application.Installing then
Application.Initialize;


From what I understand, if both Application.DelayInitialize and Application.Installing are True, then it will go ahead and Initialize the service application. I don't understand why it would be initialized in this scenario - I'm pretty sure it shouldn't be initialized.



Can someone give me some clarification what I'm looking at here?





On a side note, I would never need to enable DelayInitialize as there's no need to be concerned with Server 2003. I would just like to understand what this code is actually meant to do the way it's written.










share|improve this question
















When creating a new Windows Service in Delphi, it inserts the following:



if not Application.DelayInitialize or Application.Installing then
Application.Initialize;


The author didn't bother including parentheses, so I'm trying to wrap my head around this. It translates to:



if (not Application.DelayInitialize) or Application.Installing then
Application.Initialize;


From what I understand, if both Application.DelayInitialize and Application.Installing are True, then it will go ahead and Initialize the service application. I don't understand why it would be initialized in this scenario - I'm pretty sure it shouldn't be initialized.



Can someone give me some clarification what I'm looking at here?





On a side note, I would never need to enable DelayInitialize as there's no need to be concerned with Server 2003. I would just like to understand what this code is actually meant to do the way it's written.







delphi if-statement service






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 1:14









Remy Lebeau

342k19267461




342k19267461










asked Nov 28 '18 at 23:00









Jerry DodgeJerry Dodge

15.4k22112267




15.4k22112267








  • 1





    not operator has higher precedence.

    – LU RD
    Nov 28 '18 at 23:07








  • 1





    Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

    – GolezTrol
    Nov 28 '18 at 23:12













  • Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

    – MartynA
    Nov 28 '18 at 23:15













  • Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

    – LU RD
    Nov 28 '18 at 23:18











  • "... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

    – Sertac Akyuz
    Nov 28 '18 at 23:29














  • 1





    not operator has higher precedence.

    – LU RD
    Nov 28 '18 at 23:07








  • 1





    Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

    – GolezTrol
    Nov 28 '18 at 23:12













  • Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

    – MartynA
    Nov 28 '18 at 23:15













  • Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

    – LU RD
    Nov 28 '18 at 23:18











  • "... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

    – Sertac Akyuz
    Nov 28 '18 at 23:29








1




1





not operator has higher precedence.

– LU RD
Nov 28 '18 at 23:07







not operator has higher precedence.

– LU RD
Nov 28 '18 at 23:07






1




1





Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

– GolezTrol
Nov 28 '18 at 23:12







Looks like Application.DelayInitialize can postpone initialization, but Application.Installing overrides that, so even if DelayInitialize is set, it will still initialize the application when it is installing. Bit hard to tell if that was indeed the intention, but I would interpret it like that. Your conclusions are right, btw. It's indeed the same as the second variation, with not only applying to the first bool. And as LU RD mentioned, that's documented behavior.

– GolezTrol
Nov 28 '18 at 23:12















Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

– MartynA
Nov 28 '18 at 23:15







Jerry, it's like @LURD says, it's determined by operator precedence. One way to think about that is that operators of higher precedence bind "more tightly" than lower ones. So in your expression, not bool1 is evaluated before the or bool2 gets a chance to get a look in. Not my dv, btw. See docwiki.embarcadero.com/RADStudio/Tokyo/en/…

– MartynA
Nov 28 '18 at 23:15















Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

– LU RD
Nov 28 '18 at 23:18





Jerry, think of it like a mathematical expression: y = 2*x +a. The multiplicator operator has higher precedence than the addition operator.

– LU RD
Nov 28 '18 at 23:18













"... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

– Sertac Akyuz
Nov 28 '18 at 23:29





"... some clarification what I'm looking at here?" That's the problem, it's not clear. With all that unnecessary testing code it looks like you're trying to figure out operator precedence (hence the downvotes) while in fact you're probably (?) asking about service application initialization.

– Sertac Akyuz
Nov 28 '18 at 23:29












1 Answer
1






active

oldest

votes


















2














As the comment inserted in the project source when you create a service application explains, DelayInitialize exists for a specific reason: the requirement to call StartServiceCtrlDispatcher before CoRegisterClassObject. Whether you would need to set it or not, I presume, would really depend on if you need to call CoRegisterClassObject, not if you're targeting server 2003 or not (*). IOW, I wouldn't expect that comment to be updated with every new server version. YMMV, testing might be required.



The implied design here is that you use System.InitProc to call CoRegisterClassObject (**), similar to how the CoInitializeEx call is made by ComObj.pas. InitProc is called from Vcl.Forms.Application.Initialize which is called from Vcl.SvcMgr.TServiceApplication.Initialize.



Now, when Vcl.SvcMgr.TServiceApplication.Installing returns true, that means StartServiceCtrlDispatcher will not to be called. Because the main thread is not going to connect with the service control manager. Instead it will either install or uninstall services and then exit. Then the need for any delayed initialization will become void and in fact a delayed initialization cannot run since no service thread will run (***).



And so this is why the expression is written the way it is, there are no forgotten/missing parenthesis.






(*) D2007 has the comment at which time 2003 R2 is the last server.




(**) From the comment in the project source:



Windows 2003 Server requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject, which can be called indirectly by Application.Initialize.




(***) This is where a delayed initialization is called, guarded by a flag in case there is more than one service in the executable.






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%2f53529393%2fhow-does-this-if-not-statement-work-without-parentheses-in-a-new-service-appli%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    As the comment inserted in the project source when you create a service application explains, DelayInitialize exists for a specific reason: the requirement to call StartServiceCtrlDispatcher before CoRegisterClassObject. Whether you would need to set it or not, I presume, would really depend on if you need to call CoRegisterClassObject, not if you're targeting server 2003 or not (*). IOW, I wouldn't expect that comment to be updated with every new server version. YMMV, testing might be required.



    The implied design here is that you use System.InitProc to call CoRegisterClassObject (**), similar to how the CoInitializeEx call is made by ComObj.pas. InitProc is called from Vcl.Forms.Application.Initialize which is called from Vcl.SvcMgr.TServiceApplication.Initialize.



    Now, when Vcl.SvcMgr.TServiceApplication.Installing returns true, that means StartServiceCtrlDispatcher will not to be called. Because the main thread is not going to connect with the service control manager. Instead it will either install or uninstall services and then exit. Then the need for any delayed initialization will become void and in fact a delayed initialization cannot run since no service thread will run (***).



    And so this is why the expression is written the way it is, there are no forgotten/missing parenthesis.






    (*) D2007 has the comment at which time 2003 R2 is the last server.




    (**) From the comment in the project source:



    Windows 2003 Server requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject, which can be called indirectly by Application.Initialize.




    (***) This is where a delayed initialization is called, guarded by a flag in case there is more than one service in the executable.






    share|improve this answer






























      2














      As the comment inserted in the project source when you create a service application explains, DelayInitialize exists for a specific reason: the requirement to call StartServiceCtrlDispatcher before CoRegisterClassObject. Whether you would need to set it or not, I presume, would really depend on if you need to call CoRegisterClassObject, not if you're targeting server 2003 or not (*). IOW, I wouldn't expect that comment to be updated with every new server version. YMMV, testing might be required.



      The implied design here is that you use System.InitProc to call CoRegisterClassObject (**), similar to how the CoInitializeEx call is made by ComObj.pas. InitProc is called from Vcl.Forms.Application.Initialize which is called from Vcl.SvcMgr.TServiceApplication.Initialize.



      Now, when Vcl.SvcMgr.TServiceApplication.Installing returns true, that means StartServiceCtrlDispatcher will not to be called. Because the main thread is not going to connect with the service control manager. Instead it will either install or uninstall services and then exit. Then the need for any delayed initialization will become void and in fact a delayed initialization cannot run since no service thread will run (***).



      And so this is why the expression is written the way it is, there are no forgotten/missing parenthesis.






      (*) D2007 has the comment at which time 2003 R2 is the last server.




      (**) From the comment in the project source:



      Windows 2003 Server requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject, which can be called indirectly by Application.Initialize.




      (***) This is where a delayed initialization is called, guarded by a flag in case there is more than one service in the executable.






      share|improve this answer




























        2












        2








        2







        As the comment inserted in the project source when you create a service application explains, DelayInitialize exists for a specific reason: the requirement to call StartServiceCtrlDispatcher before CoRegisterClassObject. Whether you would need to set it or not, I presume, would really depend on if you need to call CoRegisterClassObject, not if you're targeting server 2003 or not (*). IOW, I wouldn't expect that comment to be updated with every new server version. YMMV, testing might be required.



        The implied design here is that you use System.InitProc to call CoRegisterClassObject (**), similar to how the CoInitializeEx call is made by ComObj.pas. InitProc is called from Vcl.Forms.Application.Initialize which is called from Vcl.SvcMgr.TServiceApplication.Initialize.



        Now, when Vcl.SvcMgr.TServiceApplication.Installing returns true, that means StartServiceCtrlDispatcher will not to be called. Because the main thread is not going to connect with the service control manager. Instead it will either install or uninstall services and then exit. Then the need for any delayed initialization will become void and in fact a delayed initialization cannot run since no service thread will run (***).



        And so this is why the expression is written the way it is, there are no forgotten/missing parenthesis.






        (*) D2007 has the comment at which time 2003 R2 is the last server.




        (**) From the comment in the project source:



        Windows 2003 Server requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject, which can be called indirectly by Application.Initialize.




        (***) This is where a delayed initialization is called, guarded by a flag in case there is more than one service in the executable.






        share|improve this answer















        As the comment inserted in the project source when you create a service application explains, DelayInitialize exists for a specific reason: the requirement to call StartServiceCtrlDispatcher before CoRegisterClassObject. Whether you would need to set it or not, I presume, would really depend on if you need to call CoRegisterClassObject, not if you're targeting server 2003 or not (*). IOW, I wouldn't expect that comment to be updated with every new server version. YMMV, testing might be required.



        The implied design here is that you use System.InitProc to call CoRegisterClassObject (**), similar to how the CoInitializeEx call is made by ComObj.pas. InitProc is called from Vcl.Forms.Application.Initialize which is called from Vcl.SvcMgr.TServiceApplication.Initialize.



        Now, when Vcl.SvcMgr.TServiceApplication.Installing returns true, that means StartServiceCtrlDispatcher will not to be called. Because the main thread is not going to connect with the service control manager. Instead it will either install or uninstall services and then exit. Then the need for any delayed initialization will become void and in fact a delayed initialization cannot run since no service thread will run (***).



        And so this is why the expression is written the way it is, there are no forgotten/missing parenthesis.






        (*) D2007 has the comment at which time 2003 R2 is the last server.




        (**) From the comment in the project source:



        Windows 2003 Server requires StartServiceCtrlDispatcher to be called before CoRegisterClassObject, which can be called indirectly by Application.Initialize.




        (***) This is where a delayed initialization is called, guarded by a flag in case there is more than one service in the executable.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 29 '18 at 18:54

























        answered Nov 29 '18 at 15:12









        Sertac AkyuzSertac Akyuz

        48.7k373131




        48.7k373131
































            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%2f53529393%2fhow-does-this-if-not-statement-work-without-parentheses-in-a-new-service-appli%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

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks