Recent

Author Topic: Dialogs - QuestionDlg ...  (Read 3525 times)

seghele0

  • Full Member
  • ***
  • Posts: 137
Dialogs - QuestionDlg ...
« on: November 07, 2021, 04:09:44 pm »
I'm just an amateur programmer who tries to understand Pascal and program everything through self-study and 'Google (Forums)'. My knowledge is really limited.
It would be a good idea to be able to choose a bitmap for the buttons in a 'questiondlg' or other dialogue messages. This instead of the normal text 'yes'-'no' - or - as a supplementary option.
Perhaps this can become an additional option in the current component.
Thanks with greetings from Belgium.
 ;)


ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Dialogs - QuestionDlg ...
« Reply #1 on: November 07, 2021, 04:36:57 pm »
Hello and Welcome!

You can build your own dialogs, if you want or need to. And is possible to make them available at the component pallet too.

Check it out: https://wiki.freepascal.org/How_To_Write_Lazarus_Component

Bart

  • Hero Member
  • *****
  • Posts: 4827
    • Bart en Mariska's Webstek
Re: Dialogs - QuestionDlg ...
« Reply #2 on: November 07, 2021, 05:37:35 pm »
If you start with the CreateMessageDialog function in dialogs unit, then you have access to the underlying form.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   F: TForm;
  4.   i: Integer;
  5.   C: TComponent;
  6.   B: TBitBtn;
  7.   Res: TModalResult;
  8. begin
  9.   F := CreateMessageDialog('Dare to take a choice?', 'Do you want to format your harddrive?', mtConfirmation, [mbYes, mbNo, mbAbort, mbRetry, mbCancel, mbOK]);
  10.   for i := 0 to F.ComponentCount-1 do
  11.   begin
  12.     C := F.Components[i];
  13.     if (C is TBitBtn) then
  14.     begin
  15.       B := TBitBtn(C);
  16.       case B.Kind of
  17.         bkYes: B.Caption := 'No';
  18.         bkNo: B.Caption := 'Yes';
  19.         bkAbort: B.Caption := 'Ok';
  20.         bkRetry: B.Caption := 'Cancel';
  21.         bkCancel: B.Caption := 'Retry';
  22.         bkOk: Caption := 'Abort';
  23.       end;
  24.     end;
  25.   end;
  26.   Res := F.ShowModal;
  27.   F.Free;
  28. end;

In this simple code I change the buttons captions, just to confuse them.
You can do anything you want with the buttons now you have access to them.

I use a similar approach to have a checkbox with "Don't show this dialog anymore" on the dialog.
Note: You cannot access the components anymore after you freed the form (F in this case).

Bart

ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Dialogs - QuestionDlg ...
« Reply #3 on: November 07, 2021, 05:53:34 pm »
Nice to know about it, Bart! Thank you!

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Dialogs - QuestionDlg ...
« Reply #4 on: November 08, 2021, 10:16:16 am »
Thank you for your information.
I'll try it.
 ;)

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Dialogs - QuestionDlg ...
« Reply #5 on: November 08, 2021, 10:46:19 am »
This is my result:

With error:
Compile Project, Target: project1.exe: Exit code 1, Errors: 1
unit1.pas(34,1) Fatal: illegal character "'Â'" ($C2)
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  6. type
  7.   { TForm1 }
  8.   TForm1 = class(TForm)
  9.     Button1: TButton;
  10.     procedure Button1Click(Sender: TObject);
  11.   private
  12.   public
  13.   end;
  14. var
  15.   Form1: TForm1;
  16. implementation
  17.  
  18. {$R *.lfm}
  19.  
  20. { TForm1 }
  21.  
  22. procedure TForm1.Button1Click(Sender: TObject);
  23. var
  24.   F: TForm;
  25.   i: Integer;
  26.   C: TComponent;
  27.   B: TBitBtn;
  28.   Res: TModalResult;
  29. begin
  30.   F := CreateMessageDialog('Dare to take a choice?', 'Do you want to format your harddrive?', mtConfirmation, [mbYes, mbNo, mbAbort, mbRetry, mbCancel, mbOK]);
  31.   for i := 0 to F.ComponentCount-1 do
  32.   begin
  33.     C := F.Components[i];
  34.     if (C is TBitBtn) then
  35.     begin
  36.       B := TBitBtn(C);
  37.       case B.Kind of
  38.         bkYes: B.Caption := 'No';
  39.         bkNo: B.Caption := 'Yes';
  40.         bkAbort: B.Caption := 'Ok';
  41.         bkRetry: B.Caption := 'Cancel';
  42.         bkCancel: B.Caption := 'Retry';
  43.         bkOk: Caption := 'Abort';
  44.       end;
  45.     end;
  46.   end;
  47.   Res := F.ShowModal;
  48.   F.Free;
  49. end;
  50.  
  51. end.                        


ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Dialogs - QuestionDlg ...
« Reply #6 on: November 08, 2021, 01:18:05 pm »
Check your file with a Hex Editor, probably you will find a C2 somewhere. If true, you can replace it with 32.

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Dialogs - QuestionDlg ...
« Reply #7 on: November 08, 2021, 01:43:30 pm »
I've installed the application 'HXD Hex Editor'.
Wich file must be changed ?
 :-[

ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Dialogs - QuestionDlg ...
« Reply #8 on: November 08, 2021, 02:04:35 pm »
I've installed the application 'HXD Hex Editor'.
Wich file must be changed ?
 :-[

The file that refers to Unit1, probably Unit1.pas.

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Dialogs - QuestionDlg ...
« Reply #9 on: November 08, 2021, 04:15:32 pm »
Sorry, I see the multiple "c2" in my Unit1.pas, but I can't change them to "32".

Too bad there isn't a simple workable example on Google with your code.
 :(

ezlage

  • New Member
  • *
  • Posts: 32
  • Silence is the perfect beat!
    • GitHub
Re: Dialogs - QuestionDlg ...
« Reply #10 on: November 08, 2021, 05:13:15 pm »
Your are facing character encoding problem. You need to work around it first, I think.

seghele0

  • Full Member
  • ***
  • Posts: 137
Re: Dialogs - QuestionDlg ...
« Reply #11 on: November 08, 2021, 05:51:23 pm »
Bizarre, this would be the first time.
I do use Windows 11 now!
Personally I can't solve this problem.
So it will not be solved.
Thanks in any case.
 ::)


 

TinyPortal © 2005-2018