SysUtils.LoadPackage replaces Aplication.OnMessage handler












0














I have a main form where I set a handler for the Application.OnMessage event. (Code of this handler is placed in the main form). Then, while running the program, there can be calls to SysUtils.LoadPackage that loads some bpl-package. And after that is loaded, the handler of Application.OnMessage is changed.



I couldn't find what doing this. At least there is not right such code that goes Application.OnMessage := in the package.



One more thing: in the debugger, before LoadPackage, I see OnMessage handler described as Main.TMainForm.AppMessage. All other handlers (such as OnMinimize, OnModalBegin e.t.c.) are nil. And after LoadPackage all events have handlers, described as Vcl.AppEvnts.TMultiCaster.DoMessage.










share|improve this question




















  • 2




    The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
    – Dsm
    Nov 12 '18 at 12:09






  • 1




    Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
    – nil
    Nov 12 '18 at 12:55






  • 2




    Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
    – Sertac Akyuz
    Nov 12 '18 at 13:00








  • 1




    That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
    – GolezTrol
    Nov 12 '18 at 16:01






  • 1




    @GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
    – Remy Lebeau
    Nov 13 '18 at 6:08


















0














I have a main form where I set a handler for the Application.OnMessage event. (Code of this handler is placed in the main form). Then, while running the program, there can be calls to SysUtils.LoadPackage that loads some bpl-package. And after that is loaded, the handler of Application.OnMessage is changed.



I couldn't find what doing this. At least there is not right such code that goes Application.OnMessage := in the package.



One more thing: in the debugger, before LoadPackage, I see OnMessage handler described as Main.TMainForm.AppMessage. All other handlers (such as OnMinimize, OnModalBegin e.t.c.) are nil. And after LoadPackage all events have handlers, described as Vcl.AppEvnts.TMultiCaster.DoMessage.










share|improve this question




















  • 2




    The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
    – Dsm
    Nov 12 '18 at 12:09






  • 1




    Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
    – nil
    Nov 12 '18 at 12:55






  • 2




    Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
    – Sertac Akyuz
    Nov 12 '18 at 13:00








  • 1




    That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
    – GolezTrol
    Nov 12 '18 at 16:01






  • 1




    @GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
    – Remy Lebeau
    Nov 13 '18 at 6:08
















0












0








0







I have a main form where I set a handler for the Application.OnMessage event. (Code of this handler is placed in the main form). Then, while running the program, there can be calls to SysUtils.LoadPackage that loads some bpl-package. And after that is loaded, the handler of Application.OnMessage is changed.



I couldn't find what doing this. At least there is not right such code that goes Application.OnMessage := in the package.



One more thing: in the debugger, before LoadPackage, I see OnMessage handler described as Main.TMainForm.AppMessage. All other handlers (such as OnMinimize, OnModalBegin e.t.c.) are nil. And after LoadPackage all events have handlers, described as Vcl.AppEvnts.TMultiCaster.DoMessage.










share|improve this question















I have a main form where I set a handler for the Application.OnMessage event. (Code of this handler is placed in the main form). Then, while running the program, there can be calls to SysUtils.LoadPackage that loads some bpl-package. And after that is loaded, the handler of Application.OnMessage is changed.



I couldn't find what doing this. At least there is not right such code that goes Application.OnMessage := in the package.



One more thing: in the debugger, before LoadPackage, I see OnMessage handler described as Main.TMainForm.AppMessage. All other handlers (such as OnMinimize, OnModalBegin e.t.c.) are nil. And after LoadPackage all events have handlers, described as Vcl.AppEvnts.TMultiCaster.DoMessage.







delphi delphi-10.2-tokyo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 16:17









GolezTrol

97.9k9130174




97.9k9130174










asked Nov 12 '18 at 11:57









DaugawpilsDaugawpils

171




171








  • 2




    The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
    – Dsm
    Nov 12 '18 at 12:09






  • 1




    Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
    – nil
    Nov 12 '18 at 12:55






  • 2




    Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
    – Sertac Akyuz
    Nov 12 '18 at 13:00








  • 1




    That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
    – GolezTrol
    Nov 12 '18 at 16:01






  • 1




    @GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
    – Remy Lebeau
    Nov 13 '18 at 6:08
















  • 2




    The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
    – Dsm
    Nov 12 '18 at 12:09






  • 1




    Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
    – nil
    Nov 12 '18 at 12:55






  • 2




    Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
    – Sertac Akyuz
    Nov 12 '18 at 13:00








  • 1




    That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
    – GolezTrol
    Nov 12 '18 at 16:01






  • 1




    @GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
    – Remy Lebeau
    Nov 13 '18 at 6:08










2




2




The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
– Dsm
Nov 12 '18 at 12:09




The package implements its own Application.Onmessage handler perhaps? How can we know without knowing what is in either your application or the bpl.
– Dsm
Nov 12 '18 at 12:09




1




1




Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
– nil
Nov 12 '18 at 12:55




Including unit AppEvents will through unit's initialization create a TMultiCaster, which assigns handlers to (some or all?) TApplication events.
– nil
Nov 12 '18 at 12:55




2




2




Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
– Sertac Akyuz
Nov 12 '18 at 13:00






Set a breakpoint just after InitControls in vcl.controls.initialization. Run application. When the breakpoint is hit, set a data breakpoint for Application.FOnMessage. Run (resume) again. When the data breakpoint is hit, examine the code.
– Sertac Akyuz
Nov 12 '18 at 13:00






1




1




That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
– GolezTrol
Nov 12 '18 at 16:01




That unit contains the TApplicationEvents component, which can be used to assign application events at designtime. Because you could use multiple components, I think the unit attaches its own event handler, which then forwards any events to the event handlers assigned to all the TApplicationEvent components. It would be nice, of course, if it kept track of existing handlers, because if every bpl is going to do the same trick again, that also implies that TApplicationEvents wouldn't work well at all in applications with multiple packages...
– GolezTrol
Nov 12 '18 at 16:01




1




1




@GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
– Remy Lebeau
Nov 13 '18 at 6:08






@GolezTrol you are right that TApplicationEvents is a multicaster, it delegates TApplication events to every TApplicationEvents instance, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly. So yes, the solution to the OP's issue is to add TApplicationEvents to the MainForm.
– Remy Lebeau
Nov 13 '18 at 6:08














1 Answer
1






active

oldest

votes


















4














The package in question uses an internal instance of TApplicationEvents, which is a multicaster that intercepts TApplication events and delegates them to every TApplicationEvents instance in the application, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly.



So, to coexist with the package, the solution is to add a TApplicationEvents to your MainForm and assign a handler to its OnMessage event, instead of assigning a handler to the TApplication.OnMessage event directly.






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%2f53261689%2fsysutils-loadpackage-replaces-aplication-onmessage-handler%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









    4














    The package in question uses an internal instance of TApplicationEvents, which is a multicaster that intercepts TApplication events and delegates them to every TApplicationEvents instance in the application, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly.



    So, to coexist with the package, the solution is to add a TApplicationEvents to your MainForm and assign a handler to its OnMessage event, instead of assigning a handler to the TApplication.OnMessage event directly.






    share|improve this answer


























      4














      The package in question uses an internal instance of TApplicationEvents, which is a multicaster that intercepts TApplication events and delegates them to every TApplicationEvents instance in the application, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly.



      So, to coexist with the package, the solution is to add a TApplicationEvents to your MainForm and assign a handler to its OnMessage event, instead of assigning a handler to the TApplication.OnMessage event directly.






      share|improve this answer
























        4












        4








        4






        The package in question uses an internal instance of TApplicationEvents, which is a multicaster that intercepts TApplication events and delegates them to every TApplicationEvents instance in the application, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly.



        So, to coexist with the package, the solution is to add a TApplicationEvents to your MainForm and assign a handler to its OnMessage event, instead of assigning a handler to the TApplication.OnMessage event directly.






        share|improve this answer












        The package in question uses an internal instance of TApplicationEvents, which is a multicaster that intercepts TApplication events and delegates them to every TApplicationEvents instance in the application, allowing multiple Forms, components, etc to receive the same app events without stepping on each other's toes trying to assign handlers to TApplication directly.



        So, to coexist with the package, the solution is to add a TApplicationEvents to your MainForm and assign a handler to its OnMessage event, instead of assigning a handler to the TApplication.OnMessage event directly.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 6:13









        Remy LebeauRemy Lebeau

        332k18251443




        332k18251443






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53261689%2fsysutils-loadpackage-replaces-aplication-onmessage-handler%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

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation