Recent

Author Topic: No icons/glyphs in QuestionDlg buttons  (Read 5488 times)

Porbitz

  • New Member
  • *
  • Posts: 14
No icons/glyphs in QuestionDlg buttons
« on: September 13, 2018, 06:46:25 pm »
Hi All,

When using QuestionDlg, the buttons in it have no icons, regardless of the type of message and button I use, even if I specify to always show them for buttons (see attached screenshot).

The following code produces the attached screenshot,
Code: Pascal  [Select][+][-]
  1. questionDlg('Can''t proceed','What is your username?',mtError,[mrYes,'Okay, I''ll give it'],0);

I have Lazarus 1.8.4 on a Windows 10.

Is there a way I can show the icons on the buttons in such an environment? What I want, basically, is to show a dialog, with icons for type (as in mtError or mtWarning), that allows me to customize the buttons' captions and show the correct icon in them... am I asking for too much? :D

Many thanks!!

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: No icons/glyphs in QuestionDlg buttons
« Reply #1 on: September 13, 2018, 11:56:11 pm »
Try a MessageDlg instead..
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: No icons/glyphs in QuestionDlg buttons
« Reply #2 on: September 14, 2018, 12:55:18 am »
No, MessageDlg is widget-set controlled, too.

But there is a function CreateMessageDialog which is not. So, try this one:
Code: Pascal  [Select][+][-]
  1. function MyQuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  2.             Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult;
  3. begin
  4.   with CreateMessageDialog(aCaption, aMsg, DlgType, Buttons) do
  5.     try
  6.       HelpContext := HelpCtx;
  7.       Result := ShowModal;
  8.     finally
  9.       Free;
  10.     end;
  11. end;

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: No icons/glyphs in QuestionDlg buttons
« Reply #3 on: September 14, 2018, 02:07:38 pm »
No, MessageDlg is widget-set controlled, too.

But there is a function CreateMessageDialog which is not. So, try this one:
Code: Pascal  [Select][+][-]
  1. function MyQuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  2.             Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult;
  3. begin
  4.   with CreateMessageDialog(aCaption, aMsg, DlgType, Buttons) do
  5.     try
  6.       HelpContext := HelpCtx;
  7.       Result := ShowModal;
  8.     finally
  9.       Free;
  10.     end;
  11. end;

I tryed it on Lazarus 1.8.4, but I get error on parameter aCaption of CreateMessageDialog:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. function MyQuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  33.             Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult;
  34. begin
  35.   // unit Dialogs;
  36.   // function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  37.   //            Buttons: TMsgDlgButtons): TForm; overload;
  38.  
  39.   // Error on parameter
  40.   // with CreateMessageDialog(aCaption, aMsg, DlgType, Buttons) do
  41.  
  42.   with CreateMessageDialog(aMsg, DlgType, Buttons) do
  43.     try
  44.       HelpContext := HelpCtx;
  45.       Result := ShowModal;
  46.     finally
  47.       Free;
  48.     end;
  49. end;
  50.  
  51. procedure TForm1.Button1Click(Sender: TObject);
  52. begin
  53.   // Error on parameter
  54.   // MyQuestionDlg('Can''t proceed','What is your username?', mtError, [mrYes, 'Okay, I''ll give it'],0);
  55.  
  56.   // Even changing from mrYes to mbYes, error continues
  57.   // MyQuestionDlg('Can''t proceed','What is your username?', mtError, [mbYes, 'Okay, I''ll give it'],0);
  58.  
  59.   MyQuestionDlg('Can''t proceed','What is your username?', mtError, [mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
  60.                     mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose], 0);
  61.  
  62.   // No customized caption at the end
  63. end;
  64.  
  65. end.

Porbitz

  • New Member
  • *
  • Posts: 14
Re: No icons/glyphs in QuestionDlg buttons
« Reply #4 on: September 14, 2018, 02:58:51 pm »
Thanks Jamie and WP for the responses. I get the same as Valdir.

CreateMessageDialog is defined as

Code: Pascal  [Select][+][-]
  1. function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
  2.             Buttons: TMsgDlgButtons): TForm; overload;

So it doesn't take a caption, nor it seems to allow button customization. Or am I missing something here, wp?

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: No icons/glyphs in QuestionDlg buttons
« Reply #5 on: September 14, 2018, 03:01:18 pm »
I see - this seems to be a change in Laz trunk with implements two overloaded versions (I am usually working with trunk). But easy to fix: Use the CreateMessageDialog of 1.8.4 (without the caption parameter) and assign the caption later when the form is created:

Code: Pascal  [Select][+][-]
  1. function MyQuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  2.             Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult;
  3. begin
  4.   with CreateMessageDialog(aMsg, DlgType, Buttons) do
  5.     try
  6.       Caption := ACaption;
  7.       HelpContext := HelpCtx;
  8.       Result := ShowModal;
  9.     finally
  10.       Free;
  11.     end;
  12. end;

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: No icons/glyphs in QuestionDlg buttons
« Reply #6 on: September 14, 2018, 03:07:47 pm »
I see - this seems to be a change in Laz trunk with implements two overloaded versions (I am usually working with trunk). But easy to fix: Use the CreateMessageDialog of 1.8.4 (without the caption parameter) and assign the caption later when the form is created:

Code: Pascal  [Select][+][-]
  1. function MyQuestionDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
  2.             Buttons: TMsgDlgButtons; HelpCtx: Longint): TModalResult;
  3. begin
  4.   with CreateMessageDialog(aMsg, DlgType, Buttons) do
  5.     try
  6.       Caption := ACaption;
  7.       HelpContext := HelpCtx;
  8.       Result := ShowModal;
  9.     finally
  10.       Free;
  11.     end;
  12. end;
Worked. Thanks.

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: No icons/glyphs in QuestionDlg buttons
« Reply #7 on: September 14, 2018, 03:29:08 pm »
I am using this unit:
Code: Pascal  [Select][+][-]
  1. unit ProgramMessages;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Dialogs, Forms;
  9.  
  10. function MsgErrorAR(const aMsg: String): TModalResult;
  11. procedure MsgError(const aMsg: String);
  12. procedure MsgWarning(const aMsg: String);
  13. function MsgConfirmation(const aMsg: String; Buttons: TMsgDlgButtons = mbYesNoCancel): TModalResult;
  14. procedure MsgInformation(const aMsg: String);
  15.  
  16. implementation
  17.  
  18. function MessageDlgBB(const aMsg: string; DlgType: TMsgDlgType;
  19.   Buttons: TMsgDlgButtons): TModalResult;
  20. begin
  21.   with CreateMessageDialog(aMsg, DlgType, Buttons) do
  22.   begin
  23.     Result := ShowModal;
  24.     Free;
  25.   end;
  26. end;
  27.  
  28. function MsgErrorAR(const aMsg: String): TModalResult;
  29. begin
  30.   Result := MessageDlgBB(aMsg, mtError, [mbAbort, mbRetry]);
  31. end;
  32.  
  33. procedure MsgError(const aMsg: String);
  34. begin
  35.   MessageDlgBB(aMsg, mtError, [mbOK]);
  36. end;
  37.  
  38. procedure MsgWarning(const aMsg: String);
  39. begin
  40.   MessageDlgBB(aMsg, mtWarning, [mbOK]);
  41. end;
  42.  
  43. function MsgConfirmation(const aMsg: String; Buttons: TMsgDlgButtons): TModalResult;
  44. begin
  45.   Result := MessageDlgBB(aMsg, mtConfirmation, Buttons);
  46. end;
  47.  
  48. procedure MsgInformation(const aMsg: String);
  49. begin
  50.   MessageDlgBB(aMsg, mtInformation, [mbOK]);
  51. end;
  52.  
  53. end.
  54.  
  55.  
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: No icons/glyphs in QuestionDlg buttons
« Reply #8 on: September 14, 2018, 03:52:39 pm »
Where is the picture/icon resource in there?
Specialize a type, not a var.

Milsa

  • Sr. Member
  • ****
  • Posts: 309
Re: No icons/glyphs in QuestionDlg buttons
« Reply #9 on: September 14, 2018, 04:33:15 pm »
I don't know that I understand you.

If you want standard icons, use second parameter in MessageDlgBB.
« Last Edit: September 14, 2018, 04:38:34 pm by Milsa »
I work with Lazarus 2.2.2, FPC 3.2.2, date 2022-05-15
This information is actual to: 28st Dec 2022

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: No icons/glyphs in QuestionDlg buttons
« Reply #10 on: September 14, 2018, 04:49:01 pm »
Where is the picture/icon resource in there?
The buttons created by CreateMessageDialog are TBitBtn's, and they get the icon from the internal LCL resource depending on the button's Kind.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: No icons/glyphs in QuestionDlg buttons
« Reply #11 on: September 14, 2018, 10:01:29 pm »
I think Porbitz was after a question dialog that offers a variable number of user-defined buttons, each having both a supplied caption and an icon which reflects its modal result value.
AFAIK this is not available in the LCL.
The attached project supplies one. You can optionally make the dialog message bold.

Porbitz

  • New Member
  • *
  • Posts: 14
Re: No icons/glyphs in QuestionDlg buttons
« Reply #12 on: September 17, 2018, 11:27:54 am »
Thanks howardpc, that's exactly what I need!!!  :D

One thing though, trying to compile it, Lazarus tells me it can't find the unit UITypes. I looked for it in the Install Package and the Online Package Manager, as well as googled it; the closest I could see is the System.UITypes lib, but that's for Delphi. Any idea where I can find it?

Many thanks again, amazing work!

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: No icons/glyphs in QuestionDlg buttons
« Reply #13 on: September 17, 2018, 12:32:59 pm »
Provided the LCL is specified as a package dependency in your project, the IDE should find UITypes immediately in recent Lazarus versions.
What version of Lazarus are you using?
Perhaps if you use an older version before TModalResult types were reorganised there is no UITypes. In which case just delete UITypes altogether, it would not be needed.
« Last Edit: September 17, 2018, 12:37:47 pm by howardpc »

 

TinyPortal © 2005-2018