Code works in TMemo but not TSynEditMemo (Exception) lazarus / 31-LCL ---------------------------------------------------------------------- MisterKode · 2011-04-25 07:08 Hi everyone Trying to track down the following code that is causing this problem and can't put my finger on it - works great with a TMemo, but throws the exception: Project raised exception class 'ESynEditStringList' with message: Invalid stringlist index 1 Here's the code I originally wrote for the TMemo which does this: Code: [Select]{Start SynEditMEMO}  i := 0;   if GroupNameEdit.Text <> '' then   begin     repeat       begin         SynMEMO1.Lines.Strings[i] := '';         i := i + 1;       end     until i = ImagesLBX.Count; {10th Dec 09 - removed -1}   end   else   begin     repeat       begin         SynMEMO1.Lines.Strings[i] := '';         i := i + 1;       end     until i = ImagesLBX.Count; {10th Dec 09 - removed -1}   end; I'm sure I needed i := i + 1; for this Memo as well, or not? Thanks Carl ---------------------------------------------------------------------- fabienwang · 2011-04-25 08:35 Indeed you need to do the i:=i+1 in a repeat...until (you wouldn't in a for). You just need to put until i = ImagesLBX.Count - 1 (i don't know why you removed it ?!) ---------------------------------------------------------------------- Martin_fr · 2011-04-25 08:38 It should be   SynMEMO1.Lines instead of   SynMEMO1.Lines.Strings But even this will fail. SynEdit doesn't auto add new lines. (except for an empty synedit, allows access to lines[0], IIRC) Check Lines.Count, and use Lines.Add, if needed ---------------------------------------------------------------------- MisterKode · 2011-04-25 09:28 Quote from: FabienWang on April 25, 2011, 10:35:19 amIndeed you need to do the i:=i+1 in a repeat...until (you wouldn't in a for). You just need to put until i = ImagesLBX.Count - 1 (i don't know why you removed it ?!) I removed it because it would grab one less line from the list box for procesing in the memo. I think Leledumbo helped me with that in January ---------------------------------------------------------------------- MisterKode · 2011-04-25 09:41 Quote from: Martin_fr on April 25, 2011, 10:38:18 amIt should be   SynMEMO1.Lines instead of   SynMEMO1.Lines.Strings But even this will fail. SynEdit doesn't auto add new lines. (except for an empty synedit, allows access to lines[0], IIRC) Check Lines.Count, and use Lines.Add, if needed Thanks so much Martin! I ended up using SynMEMO1.Lines and then after adding each line used GeneratedCodeSEMemo.Lines.Add('') -- finally using GeneratedCodeSEMemo.Lines.Delete(i) to remove the extra line created in the memo