Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-09

MessageDlg() return type

14 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Why is MessageDlg()'s return type a Integer and not a TMsgDlgBtn or TModalResult type?

Surely the return type expect must be one of the TMsgDlgBtn or TModalResult enum types?

Regards,
- Graeme -

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 7 lines
Hi, Why is MessageDlg()'s return type a Integer and not a TMsgDlgBtn or TModalResult type? Surely the return type expect must be one of the TMsgDlgBtn or TModalResult enum types?
TModalResult = low(Integer)..high(Integer);

I changed the result type to TModalResult.

Note: QuestionDlg can return any TModalResult, not only the predefined constants.

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
TModalResult = low(Integer)..high(Integer); I changed the result type to TModalResult.

OK, that makes more sense.

Now what return result is TWidgetSet.PromptUser() supposed to return? Also a TModalResult?

The reason I ask, is because in fpGUI the return result of a TfpgMessageDialog is a button type (the button the user clicked), and I need to know how to map that button type to a LongInt (or LCL TModalResult) or whatever PromptUser() must return.

Regards,
- Graeme -

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Now what return result is TWidgetSet.PromptUser() supposed to return?

OK, from the LCL API help it says MessageDlg returns the button the user pressed - expressed as an integer.

http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/messagedlg.html

wouldn't it also be better to define .PromptUser()'s return type as a TMsgDlgBtn type? Thus removing any possible confusion.

NOTE:
The help doesn't seem to make sense in reality - or maybe I'm just not understanding LCL workings very well (quite possible).

Button enums are defined as follows...

TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,

                     mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose);

I wrote code as follows...

   Result := MessageDlg('My caption','error dialog with custom buttons',
mtError, [mbOK, mbYesToAll, mbAbort, mbHelp], '');
   Writeln('Result = ', Result);

At runtime I click on the "Abort" button and the console output is 3 ???? I'm using LCL-GTK2.

So what is 3? It's not the enum value of mbAbort, it is also not the set value of mbAbort in the button set I passed to MessageDlg(). Sets start from value zero correct? So where does the value 3 come from?

Regards,
- Graeme -

Reply by email

Giuliano Colla
to Graeme Geldenhuys

Il 12/09/2012 16:44, Graeme Geldenhuys ha scritto:

Show quoted text 10 lines
At runtime I click on the "Abort" button and the console output is 3 ???? I'm using LCL-GTK2. So what is 3? It's not the enum value of mbAbort, it is also not the set value of mbAbort in the button set I passed to MessageDlg(). Sets start from value zero correct? So where does the value 3 come from?

TmodalResult is just a set of Integers.

 From the Forms Unit: TModalResult = low(Integer)..high(Integer);

That way it allows you to define any custom Modal Result for your own purposes in modal forms, besides the first predefined 12 values.

From the unit Controls of Lazarus LCL:

const
   mrNone = 0;
   mrOK = mrNone + 1;
   mrCancel = mrNone + 2;
   mrAbort = mrNone + 3;
   mrRetry = mrNone + 4;
   mrIgnore = mrNone + 5;
   mrYes = mrNone + 6;
   mrNo = mrNone + 7;
   mrAll = mrNone + 8;
   mrNoToAll = mrNone + 9;
   mrYesToAll = mrNone + 10;
   mrClose = mrNone + 11;
   mrLast = mrClose;

mrAbort is a modal result which may derive from a dialog, but also from a custom modal form. It has nothing to do with mbAbort, which is a just an enumerated Button type for a Message dialog.
bkAbort is a TBitBtn Kind, which is different from both mbAbort and mrAbort.

I believe that this has to do with Delphi compatibility, but it makes sense nonetheless.

Giuliano

Reply by email

Graeme Geldenhuys
to Giuliano Colla
Giuliano Colla wrote
mrAbort is a modal result which may derive from a dialog, but also from a custom modal form. It has nothing to do with mbAbort, which is a just

I don't know, from a developer point of those, those two seem to be a lot related (or maybe that's just me).

I believe that this has to do with Delphi compatibility, but it makes sense nonetheless.

I don't know, it all sounds pretty confusing to me! :)

Anyway... looking deeper into the widgetset implementations, it seems internally TWidgetset.PromptUser must return a idButtonXXX type - yet another type (plus more confusion)! Then later idButtonXXX gets converted somewhere to a TModalResult (I think). So why couldn't TWidgetset.PromptUser not simply return a TModalResult in the first place??

And to implement LCL-fpGUI's PromtUser() support, a mbHelp button click must return a idButtonHelp, which then later gets translated to mrNone (as far as I can see). The LCL-fpGUI's return results now finally seem consistent with LCL-GTK2's implementation.

Simply defining two types (buttons and modal results with logical mapping between them) and being consistent with those types throughout the LCL would have been a MUCH CLEANER implementation than the mess I currently see.

Anyway, I think I figure all this return types out now - using lots and lots of trial and error.

Regards,
- Graeme -

Reply by email

Giuliano Colla
to Hans-Peter Diettrich: I'd suggest to base both the button types and modal results on the same enum. Eventually…

Il 12/09/2012 18:07, Hans-Peter Diettrich ha scritto:

Show quoted text 7 lines
I'd suggest to base both the button types and modal results on the same enum. Eventually mrNone will be excluded from the buttons set (no mbNone). mr/mbHelp should be returned only when the dialog didn't handle it already.

If Lazarus must keep even a minimum of Delphi compatibility, that's not possible.

Giuliano

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys: OK, that makes more sense. Now what return result is TWidgetSet.PromptUser() supposed to…
Show quoted text 16 lines
On 12/09/12 15:03, Mattias Gaertner wrote: > > TModalResult = low(Integer)..high(Integer); > > I changed the result type to TModalResult. OK, that makes more sense. Now what return result is TWidgetSet.PromptUser() supposed to return? Also a TModalResult? The reason I ask, is because in fpGUI the return result of a TfpgMessageDialog is a button type (the button the user clicked), and I need to know how to map that button type to a LongInt (or LCL TModalResult) or whatever PromptUser() must return.

I'd suggest to base both the button types and modal results on the same enum. Eventually mrNone will be excluded from the buttons set (no mbNone). mr/mbHelp should be returned only when the dialog didn't handle it already.

DoDi

Reply by email

Giuliano Colla
to Graeme Geldenhuys: I don't know, from a developer point of those, those two seem to be a lot related (or…

Il 12/09/2012 17:31, Graeme Geldenhuys ha scritto:

Show quoted text 8 lines
On 12/09/12 16:09, Giuliano Colla wrote: > mrAbort is a modal result which may derive from a dialog, but also from > a custom modal form. It has nothing to do with mbAbort, which is a just I don't know, from a developer point of those, those two seem to be a lot related (or maybe that's just me).

From another developer's point of view.

If you're not satisfied with a custom dialog, which is intended for minimal standard usage, then you're forced to create your own dialog: a modal form, with the buttons and controls you need (I always end up that way, except a few trivial cases), which will return a value.

You don't have any use of the mbOK..mbClose set which is just to describe the look of a standard dialog.

To close the form maybe you'll pick up a TBitButton of Kind bkAbort, or bkOk, just because the glyph is the most appropriate. But if you need to know what has been changed on the form when it closes, and maybe you need to avoid closing the form if an error has been made in an entry, depending on the situation, you'll programmatically change the Modal Result of your button to mrChangedField1 mrChangedAllFields, or to mrNone, or whatever.

Of course you'll have defined a number of custom modal results, appropriate for your applications (such as mrChanged..).

Then your

mr:=SpecialForm.ShowModal;

will return you a value which isn't related neither to a dialog button set, nor to the kind of button pressed to close the form, but to the actions taken on the form.

That's why I say that in general Modal Result, Button Kind and Button Set have nothing to do the one with the other.

Giuliano

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys: OK, from the LCL API help it says MessageDlg returns the button the user pressed -…
Show quoted text 18 lines
Button enums are defined as follows... TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose); I wrote code as follows... Result := MessageDlg('My caption','error dialog with custom buttons', mtError, [mbOK, mbYesToAll, mbAbort, mbHelp], ''); Writeln('Result = ', Result); At runtime I click on the "Abort" button and the console output is 3 ???? I'm using LCL-GTK2. So what is 3?

It's idAbort = mrAbort. Please note that TModalResult starts with mrNone=0, indicating "nothing" for a TButton.ModalResult, and "busy" as TForm.ModalResult.

DoDi

Reply by email

Mattias Gaertner
to Giuliano Colla: Il 12/09/2012 16:44, Graeme Geldenhuys ha scritto: TmodalResult is just a set of Integers.
Show quoted text 13 lines
Il 12/09/2012 16:44, Graeme Geldenhuys ha scritto: > > > At runtime I click on the "Abort" button and the console output is 3 > ???? I'm using LCL-GTK2. > > So what is 3? It's not the enum value of mbAbort, it is also not the > set value of mbAbort in the button set I passed to MessageDlg(). Sets > start from value zero correct? So where does the value 3 come from? > > TmodalResult is just a set of Integers.

a range of integer.

Show quoted text 29 lines
From the Forms Unit: TModalResult = low(Integer)..high(Integer); That way it allows you to define any custom Modal Result for your own purposes in modal forms, besides the first predefined 12 values. From the unit Controls of Lazarus LCL: const mrNone = 0; mrOK = mrNone + 1; mrCancel = mrNone + 2; mrAbort = mrNone + 3; mrRetry = mrNone + 4; mrIgnore = mrNone + 5; mrYes = mrNone + 6; mrNo = mrNone + 7; mrAll = mrNone + 8; mrNoToAll = mrNone + 9; mrYesToAll = mrNone + 10; mrClose = mrNone + 11; mrLast = mrClose; mrAbort is a modal result which may derive from a dialog, but also from a custom modal form. It has nothing to do with mbAbort, which is a just an enumerated Button type for a Message dialog. bkAbort is a TBitBtn Kind, which is different from both mbAbort and mrAbort. I believe that this has to do with Delphi compatibility, but it makes sense nonetheless.

Yes

Mattias

Reply by email

Zaher Dirkey
to Graeme Geldenhuys: Why is MessageDlg()'s return type a Integer and not a TMsgDlgBtn or TModalResult type?…
Graeme Geldenhuys wrote 12 lines
Hi, Why is MessageDlg()'s return type a Integer and not a TMsgDlgBtn or TModalResult type? Surely the return type expect must be one of the TMsgDlgBtn or TModalResult enum types? Regards, - Graeme -

I have my own message dialogs

Check it.
http://www.parmaja.com/pages/102

Best Regards
Zaher Dirkey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120913/ee861cf2/attachment.html>

Reply by email

Graeme Geldenhuys
to Zaher Dirkey
Zaher Dirkey wrote
> I have my own message dialogs

You missed the point. I wasn't trying to implement a new LCL message dialog. I was trying to implement a missing part in the LCL-fpGUI widgetset code.

With some trial and error, it is all working now.

Graeme.

Reply by email