Forum > General

How to shorten QuestionDlg calls?

(1/2) > >>

AlexTP:
I want to shorten this, by using variable for "array of const" param.
And only single QuestionDlg call.
But I don't know of what type this var must be.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  case AFlags and $0F of    MB_OK:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrOk, msgButtonOk],            0);    MB_OKCANCEL:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrOk, msgButtonOk,            mrCancel, msgButtonCancel],            0);    MB_ABORTRETRYIGNORE:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrAbort, msgButtonAbort,            mrRetry, msgButtonRetry,            mrIgnore, msgButtonIgnore],            0);    MB_YESNO:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrYes, msgButtonYes,            mrNo, msgButtonNo],            0);    MB_YESNOCANCEL:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrYes, msgButtonYes,            mrNo, msgButtonNo,            mrCancel, msgButtonCancel],            0);    MB_RETRYCANCEL:      Res:= QuestionDlg(msgTitle, AText, Typ,            [mrRetry, msgButtonRetry,            mrCancel, msgButtonCancel],            0);    else      exit(ID_CANCEL); 
Using FPC 3.2 fixes.

y.ivanov:
Unfortunately I didn't found an easy way to work with array of const. I wrote a utility class for that according to this. It encapsulates array of TVarRec and have Append/Prepend functionality.
As TVarRec needs some additional housekeeping for copying, it needs Create/Free pair, but now with advanced records t can be overhauled.

Currently it may be used like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  CA := TConstArrayAccess.Create([]);   case AFlags and $0F of    MB_OK:      begin        CA.Append([mrOk, msgButtonOk]);        Res:= QuestionDlg(msgTitle, AText, Typ, CA.AsConstArray, 0);      end;    MB_OKCANCEL:      ...  end;  CA.Free;
If that seems OK with you I can extract that class in a separate unit (because it is in a bulk with a lot more unrelated stuff) and I can share it.

MarkMLl:
So what is the actual parameter type there? Because it looks as though it should be a set rather than an array of const.

MarkMLl

Thausand:

--- Quote from: MarkMLl on July 20, 2022, 09:45:19 am ---So what is the actual parameter type there?

--- End quote ---
Array of const


--- Quote ---Because it looks as though it should be a set rather than an array of const.

--- End quote ---
Looks not important, documentation more important: https://lazarus-ccr.sourceforge.io/docs/lcl/dialogs/questiondlg.html  ;)

y.ivanov:

--- Quote from: MarkMLl on July 20, 2022, 09:45:19 am ---So what is the actual parameter type there? Because it looks as though it should be a set rather than an array of const.

MarkMLl

--- End quote ---

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TConstArray = array of TVarRec;   TConstArrayAccess = class  private    A: TConstArray;    //...  public    constructor Create(const AArray: array of const);    destructor Destroy; override;     procedure Append(const AArray: array of const);    procedure Prepend(const AArray: array of const);     property AsInteger[I: Integer]: Integer read GetAsInteger;    property AsInt64[I: Integer]: Int64 read GetAsInt64;    property AsChar[I: Integer]: Char read GetAsChar;    property AsAnsiString[I: Integer]: AnsiString read GetAsAnsiString;    property AsBoolean[I: Integer]: Boolean read GetAsBoolean;    property AsExtended[I: Integer]: Extended read GetAsExtended;    property AsDateTime[I: Integer]: TDateTime read GetAsDateTime;    property Item[I: Integer]: TVarRec read GetItem; default;    property Count: Integer read GetCount;     property AsConstArray: TConstArray read A;  end;  

Navigation

[0] Message Index

[#] Next page

Go to full version