![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 10 of 10 total |
![]() |
Mon, Sep 21 2015 1:43 PM | Permanent Link |
squiffy Telemix Ltd. | I want to create a MessageDlg event handler (used for MsgDlgResult) that can be used by many MessageDlg calls across many forms, in an attempt to remove duplicate code.
If I define my MsgDlgResult procedure within the form class everything is fine, but if I try to define it in a common module it doesn't like it. I get this error : [Error] UnitClientList.wbs (93,10): There is no function or procedure declaration that matches the MessageDlg('Please press the OK button (or refresh your browser) to log back in.', 'NOT LOGGED IN', mtError, , mbOk, refreshApp(), true) reference I assume that is because it doesn't recognise refreshApp (the handler defined in a common unit). I seem to be able to call other functions and the like in this common unit from this and other forms so I'm sure what I'm doing is broadly correct (in terms of using the unit and declaring the procedure public), but how do I get MessageDlg to use an "external" procedure in this case? Hope that makes sense. |
Mon, Sep 21 2015 2:20 PM | Permanent Link |
squiffy Telemix Ltd. | Think I've worked it out, but would appreciate someone a bit better than me passing opinion ...
In my type declarations at the start of the form, I have this : TmyProc = procedure(DlgResult: TModalResult); then further down in some method, I have : var mp: TmyProc; begin mp:=refreshApp; // This is the proc defined in another unit. ... I then use mp as the callback in the MessageDlg function. |
Mon, Sep 21 2015 2:40 PM | Permanent Link |
squiffy Telemix Ltd. | No, doesn't work. The app just crashes and restarts. No obvious error in the browser.
Still googling... |
Mon, Sep 21 2015 2:41 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | << If I define my MsgDlgResult procedure within the form class everything is fine, but if I try to define it in a common module it doesn't like it. I get this error : >> Two things: 1) You can't pass a method reference with calling parentheses. It needs to be passed like this: MessageDlg('Please press the OK button (or refresh your browser) to log back in.', 'NOT LOGGED IN', mtError, , mbOk, refreshApp, true) reference Notice that I removed the parentheses. 2) How is refreshApp defined ? Is it a method (and not just a procedure) ? Tim Young Elevate Software www.elevatesoft.com |
Mon, Sep 21 2015 2:43 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | << No, doesn't work. The app just crashes and restarts. No obvious error in the browser. >>
That's because you're trying to pass a *procedure* reference to something that expects a *method* reference. A procedure reference is missing a key piece: the instance on which the method should be called. That's why it blows up. Actually, the compiler should prevent you from doing this, but I have to do some checks to see why it isn't. Tim Young Elevate Software www.elevatesoft.com |
Mon, Sep 21 2015 2:50 PM | Permanent Link |
squiffy Telemix Ltd. | >> Notice that I removed the parentheses.
The actual code didn't have those - only the error message in the IDE when compiling. Here's the original code : MessageDlg( 'Please press the OK button' +#13+#10+'(or refresh your browser) to' +#13+#10+'log back in.','NOT LOGGED IN', mtError,[mbOk],mbOk,refreshApp,true); >> How is refreshApp defined? It is just a procedure and not a method. I'm clearly overcomplicating it. I suppose the thing to do is just create the method in the form and call the procedure from there. |
Mon, Sep 21 2015 6:03 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | << The actual code didn't have those - only the error message in the IDE when compiling. >>
Ahh, okay. I'll make sure that is corrected. << It is just a procedure and not a method. >> Yes, that's your problem. The MessageDlg parameter is an event (method) parameter, so it needs to be passed a method, and not just a procedure. << I'm clearly overcomplicating it. I suppose the thing to do is just create the method in the form and call the procedure from there. >> It doesn't have to be a method of the form, but it has to be the method of *some* class. Tim Young Elevate Software www.elevatesoft.com |
Tue, Sep 22 2015 4:36 AM | Permanent Link |
squiffy Telemix Ltd. | >> It doesn't have to be a method of the form, but it has to be the method of *some* class.
Ahhh, I get it now. Ok, I created a skeleton class like this : type TmyClass = class(TObject) public procedure SillyTest(DlgResult: TModalResult); end; Then defined a var like this : procedure ..... var myRef: TmyClass; begin myRef:=TmyClass.Create; The called it from the MessageDlg like this : MessageDlg( 'Please press the OK button' +#13+#10+'(or refresh your browser) to' +#13+#10+'log back in.','NOT LOGGED IN', mtError,[mbOk],mbOk,myRef.SillyTest,true); And it seems to work just fine. Would you mind just confirming what I've done there is correct and I'm not storing up an issue for myself? I still think it's probably overkill for this particular situation, but if nothing else I'm getting a better handle on how everything works. Thanks, Tim. Your help is, as always, greatly appreciated. |
Tue, Sep 22 2015 4:44 AM | Permanent Link |
Matthew Jones | I'd use a method on your main form - and then just reference that each
time. -- Matthew Jones |
Tue, Sep 22 2015 11:00 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. ![]() | << And it seems to work just fine. Would you mind just confirming what I've done there is correct and I'm not storing up an issue for myself? >> Yes, that's correct. Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Wednesday, March 29, 2023 at 10:59 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |