Variable number of buttons in function "QuestionDlg" with message type "mtCustom lazarus / 31-LCL ---------------------------------------------------------------------- MaxCuriosus · 2025-06-22 20:07 How can I set a variable number of custom buttons to use as follows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Var  N:Integer;  LI:LongInt;  App:String;  SL:TStringList;     {...}       SL:=TstringList.create;        SL.LoadFromFile('AppList');        N:=SL.Count-1;         LI:=QuestionDlg('Caption','Message',mtCustom,                [                  N,SL[N],                  {...}                1,SL[1],                  0,SL[0],'IsDefault'],'');       App:=SL[LI];        WriteLn(App);        SL.Free; ---------------------------------------------------------------------- Martin_fr · 2025-06-22 20:36 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  b: array of TVarRec;  s, s2: String;begin  s := 'abc';  s2 := 'foo';  SetLength(b, 4);  b[0].VType := vtInteger;  b[0].VInteger := 1;  b[1].VType := vtAnsiString;  b[1].VAnsiString := pointer(s);   b[2].VType := vtInteger;  b[2].VInteger := 2;  b[3].VType := vtAnsiString;  b[3].VAnsiString := pointer(s2);  QuestionDlg('a','b', mtConfirmation, b,0);end;  You can change the length of b as needed, to add as many pairs as you want. Mind, that you pass the string as pointer. It will therefore not be refcounted. So you must keep the original string for the duration of the call, and you must NOT modify it in any way. E.g. if above you did "s:= s +'bar';" after setting b[1], then you risk seeing trash or getting a crash. The danger is, that it may work at random. But it will sometimes break. ---------------------------------------------------------------------- Martin_fr · 2025-06-22 21:07 If you need that many choices, maybe better use TTaskDialog? There are quick helper methods named:   TaskDlg(); They can offer items in a list with radio buttons. ---------------------------------------------------------------------- ASerge · 2025-06-23 04:12 Example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.btnTestClick(Sender: TObject);var  SL: TStringList;  VA: array of TVarRec;  iL, iV: SizeInt;begin  SL := TStringList.Create;  try    SL.Append('One');    SL.Append('Two');    SL.Append('Three');    // Make array of TVarRec    SetLength(VA, SL.Count * 2 + 1);    iV := 0;    for iL := SL.Count - 1 downto 0 do    begin      with VA[iV] do    begin        VType := vtInteger;        VInteger := iL;      end;    Inc(iV);      with VA[iV] do      begin        VType := vtAnsiString;        VAnsiString := Pointer(SL[iL]);      end;      Inc(iV);    end;    with VA[iV] do    begin      VType := vtAnsiString;      VAnsiString := Pointer(string('IsDefault'));    end;    QuestionDlg('Caption', 'Message', mtCustom, VA, '');  finally    SL.Free;  end;end; ---------------------------------------------------------------------- Thaddy · 2025-06-23 04:59 Quote from: Martin_fr on June 22, 2025, 10:36:55 pmMind, that you pass the string as pointer. It will therefore not be refcounted. So you must keep the original string for the duration of the call, and you must NOT modify it in any way. You can avoid that if you call UniqueString ? Although that is not strictly fully immutable, it is less of a risk. ---------------------------------------------------------------------- Martin_fr · 2025-06-23 05:41 Quote from: Thaddy on June 23, 2025, 06:59:55 amQuote from: Martin_fr on June 22, 2025, 10:36:55 pmMind, that you pass the string as pointer. It will therefore not be refcounted. So you must keep the original string for the duration of the call, and you must NOT modify it in any way. You can avoid that if you call UniqueString ? Although that is not strictly fully immutable, it is less of a risk. No need. Nothing says it must be Unique. And, you can make a copy of it. As long as it goes to another variable. Technically, you can even re-assign the original var, if you have another var that holds the original string (but I wouldn't recommend that, unless you have a very good understanding of how string ref counting and const work) ---------------------------------------------------------------------- MaxCuriosus · 2025-06-23 11:06 Martin_fr @ Reply #1, ASerge @ Reply #3, Thank you for your examples, they fully solve my case. Martin_fr @ Reply #2, For good measure I've tried the TTaskDialog. With the use of radio buttons the layout is more compact and pleasant. ---------------------------------------------------------------------- Fibonacci · 2025-06-24 02:57 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  QuestionDlg('title', 'text', mtConfirmation, [    0, 'no icon',    1, 'i1',    2, 'i2',    3, 'i3',    4, 'i4',    5, 'i5',    6, 'i6',    7, 'i7',    8, 'i8'  ], 0);end; ---------------------------------------------------------------------- ASerge · 2025-06-24 03:26 Quote from: Fibonacci on June 24, 2025, 04:57:21 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  QuestionDlg('title', 'text', mtConfirmation, [    0, 'no icon',    1, 'i1',    2, 'i2',    3, 'i3',    4, 'i4',    5, 'i5',    6, 'i6',    7, 'i7',    8, 'i8'  ], 0);end;Have you read the original question? ---------------------------------------------------------------------- Fibonacci · 2025-06-24 03:29 Quote from: ASerge on June 24, 2025, 05:26:19 amHave you read the original question? Lol not really Just read yours and Martin code and thought it could maybe be written a bit shorter