Recent

Author Topic: Dynamic number of buttons for QuestionDlg  (Read 1974 times)

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Dynamic number of buttons for QuestionDlg
« on: March 13, 2019, 11:11:28 pm »
On page
http://wiki.freepascal.org/Dialog_Examples

There are function references for MessageDLG and other dialog boxes, but not QuestionDlg.

In my application, I need two versions of a QuestionDlg, because 1 has an additional button.

Q1: Instead of hard coding, can I make the button array [] dynamic (ie add remove buttons (value and string))?

Q2: Can I make the 'IsDefault' attribute dynamic (ie move it to another value/string pair)?

TIA

Bazza
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Dynamic number of buttons for QuestionDlg
« Reply #1 on: March 14, 2019, 12:47:47 am »
Ad 1): IMO not with array of const. You can use case..of or if..then but you must hardcode parameters.
Code: Pascal  [Select][+][-]
  1. if a=1
  2.   then QuestionDlg('Cap', 'Msg', mtInformation, [mrCancel, mrOK], '')
  3.   else QuestionDlg('Cap', 'Msg', mtInformation, [mrNo, mrYes], '');
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: Dynamic number of buttons for QuestionDlg
« Reply #2 on: March 14, 2019, 07:41:28 am »
Thanks Blaazen. I thought that might be the case. Silly hard coding.
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Dynamic number of buttons for QuestionDlg
« Reply #3 on: March 14, 2019, 10:02:53 pm »
Ad 1): IMO not with array of const.
Also possible.
Code: Pascal  [Select][+][-]
  1. type
  2.   TArrayOfConst = array of TVarRec;
  3.  
  4. function CreateArrayOfConst(const A: array of const): TArrayOfConst;
  5. var
  6.   i: SizeInt;
  7. begin
  8.   SetLength(Result, Length(A));
  9.   for i := Low(A) to High(A) do
  10.     Result[i] := A[i];
  11. end;
  12.  
  13. operator + (const A, B: TArrayOfConst): TArrayOfConst;
  14. var
  15.   i, Shift: SizeInt;
  16. begin
  17.   SetLength(Result, Length(A) + Length(B));
  18.   for i := Low(A) to High(A) do
  19.     Result[i] := A[i];
  20.   Shift := Length(A);
  21.   for i := Low(B) to High(B) do
  22.     Result[i + Shift] := B[i];
  23. end;
  24.  
  25. procedure TForm1.FormCreate(Sender: TObject);
  26. var
  27.   Buttons: TArrayOfConst;
  28. begin
  29.   Buttons := CreateArrayOfConst([mrYes, mrNo]);
  30.   if 2 > 1 then
  31.     Buttons := Buttons + CreateArrayOfConst(['IsDefault']);
  32.   QuestionDlg('Caption', 'Message', mtInformation, Buttons, 0);
  33. end;

 

TinyPortal © 2005-2018