Does something about TStringLists and AddStrings affects the order of strings? lazarus / 21-General ---------------------------------------------------------------------- vfclists · 2021-02-01 10:52 I have this bit of web code I am developing. 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   tblList := TStringList.Create;  tblHeaderList := TStringList.Create;  tblTitlesList := TStringList.Create;  tblFooterList := TStringList.Create;  tblList.Sorted := False;  tblHeaderList.Sorted := False;  tblTitlesList.Sorted := False;  tblFooterList.Sorted := False;   with tblHeaderList do  begin    Clear;    AddLine('');    AddLine('');    AddLine('');  end;  tblTitlesList.Clear;  tblTitlesList.Add(GenColumnHeaders);   with tblFooterList do  begin  Clear;    AddLine('');    AddLine('');    AddLine('');    AddLine('');    AddLine('
');  end;   with tblList do  begin    AddStrings(tblHeaderList);    AddStrings(tblTitlesList);    AddStrings(tblFooterList);  end;   //tblList.SaveToFile('index.html');  //tblList.Free;  tblHeaderList.Free;  tblTitlesList.Free;  tblFooterList.Free;   AResponseInfo.ResponseNo := 200;  AResponseInfo.ContentType := 'text/html';  AResponseInfo.CharSet := 'utf-8';  //AResponseInfo.ContentType := 'text/html;charset=utf-8';  AResponseInfo.ContentText := tblList.Text;  //ancFormOne.Memo1.Lines.Clear;  //AncFormOne.Memo1.Lines.Text := tblList.Text;  outLines.Text := tblList.Text;  tblList.Free;  The problem is when this code is used to fill up tblList. 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   with tblList do  begin    AddStrings(tblHeaderList);    AddStrings(tblTitlesList);    AddStrings(tblFooterList);  end;  tblTitlesList holds the row containing the table headers and they should be within the lines, but they wind up complete outside the table region. Is there something about TStringList and AddStrings which results in that? I thought the Sorted property had something to do with it, but setting it resulted in no change. The code of tblTitlesList which should in the middle winds up at the bottom. resulting in Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        
 idtaskgrouptaskfileheadlinekeywordspricreatedscheduleddeadlineclosedoncreatedtextscheduledtextdeadlinetextclosedontextcommitidoffsetfile_path   instead of Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       
idtaskgrouptaskfileheadlinekeywordspricreatedscheduleddeadlineclosedoncreatedtextscheduledtextdeadlinetextclosedontextcommitidoffsetfile_path
---------------------------------------------------------------------- lucamar · 2021-02-01 11:51 It shouldn't, no; at least not while Sorted is False and there is no call to Sort() in between (which, btw, wouldn't result in what you see). And indeed it doesn't here. I've a piece of code very similar to the one you posted (used to prepare HTML reports and catalogs) and it has never failed yet. Fact is, I routinely use AddStrings() (which is a perfect way to add either an array of strings or another TStrings without hassle) and I've never seen it fail like yours does. Have you checked what are the contents of tblHeaderList, etc. before that piece of code? I don't see how they could be any other than what you have just set them but one never knows ... ---------------------------------------------------------------------- vfclists · 2021-02-01 16:29 mea culpa I suspected it was something I overlooked but had to ask. 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 AddLine(line: string);  begin    tblList.Add(line + #13#10);  end;  The AddLine function adds the text to the tblList function. Does the compiler issue a warning if a with statement uses a property or function which is not a method of the with item? ---------------------------------------------------------------------- Bart · 2021-02-01 19:30 Quote from: vfclists on February 01, 2021, 05:29:35 pmCode: 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 AddLine(line: string);  begin    tblList.Add(line + #13#10);  end;  The AddLine function adds the text to the tblList function. No need to add the #13#10, unless of course youy deliberately want to add an empty line tot the stringlist. Quote from: vfclists on February 01, 2021, 05:29:35 pmDoes the compiler one if a with statement uses a property or function which is not a method of the with item? Can you please rephrase that question? I cannot make head or tails from it. Bart ---------------------------------------------------------------------- lucamar · 2021-02-01 21:12 Quote from: vfclists on February 01, 2021, 05:29:35 pmDoes the compiler one if a with statement uses a property or function which is not a method of the with item? Of course: it searches everywhere following the normal rules until it finds (or not!) a correct match. Only, inside with a new rule is added: search first among the fields/methods/properties of the referenced item(s) (record, object/class, etc) That is, supposing that is what you asked ---------------------------------------------------------------------- vfclists · 2021-02-01 22:33 Quote from: vfclists on February 01, 2021, 05:29:35 pmDoes the compiler issue a warning if a with statement uses a property or function which is not one of the method or properties of  the with item? ---------------------------------------------------------------------- jamie · 2021-02-01 22:37 No, IT does not warn you if the item is outside the WITH block. That is, if the item you are addressing does not exist within the with block, it will just be happy to use what ever identifier it can find that matches your criteria.  The WITH block simply saves you from needing to specify the parent holder each time and it saves on typing, may even help the compiler to optimize a bit ---------------------------------------------------------------------- JuhaManninen · 2021-02-01 23:17 vfclists, don't use WITH blocks. ---------------------------------------------------------------------- ASerge · 2021-02-01 23:33 Quote from: vfclists on February 01, 2021, 11:52:07 amI thought the Sorted property had something to do with it, but setting it resulted in no change. The Sorted property has nothing to do with it. The result corresponds to what you have coded. The first "with" fills the tblList with three lines. The tblHeaderList remains cleared. Next, the tblTitlesList is filled with column headers. The second "with" adds footer lines to the tblList. The tblFooterList remains cleared. The third "with" adds the empty tblHeaderList to the tblList, then the tblTitlesList and the empty tblFooterList. The result is exactly as encoded. ---------------------------------------------------------------------- lucamar · 2021-02-02 00:39 The problem really is (as you suspected) here: 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 AddLine(line: string);begin  tblList.Add(line + #13#10);end; To expand on ASerge's answer, note that whatever is in the with statement, that procedure adds always to tblList, so when you reach: 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 with tblList do  begin    AddStrings(tblHeaderList);    AddStrings(tblTitlesList);    AddStrings(tblFooterList);  end;tblList already contains the header and footer and, since the header and footer lists are empty, that part just adds the contents of tblTitlesList to the end of tblList. Since they are constants, what I would do is to declare both "header" and "footer" as constant arrays of strings, so your code might end up being: 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 const  tblHeader: array[0..2] of String =    ('',     '',     '');  tblFooter: array [0..4] of String =    ('',     '',     '',     '',     '
'); {... and in the body of the code ..} tblList := TStringList.Create;try  tblList.AddStrings(tblHeader);  tblList.Add(GenColumnHeaders);  tblList.AddStrings(tblFooter); //  tblList.SaveToFile('index.html');//  tblList.Free;   AResponseInfo.ResponseNo := 200;  {... etc ...}  outLines.Text := tblList.Text;finally  tblList.Free;end; and you could then get rid of that "flawed" AddLine(). HTH!