Recent

Author Topic: Code works in TMemo but not TSynEditMemo (Exception)  (Read 4671 times)

MisterKode

  • New Member
  • *
  • Posts: 33
    • Stuff I like, yeh
Code works in TMemo but not TSynEditMemo (Exception)
« on: April 25, 2011, 09:08:53 am »
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] := '<a href="' + BaseURLEdit.Text +
          BaseFolderEdit.Text + ImagesLBX.Items[i] + '" ' + 'rel=' + '"' +
          GroupNameEdit.Text + '"' + '><img src="' + BaseURLEdit.Text +
          BaseFolderEdit.Text + ThumbsFolderEdit.Text + ThumbnailPrefixEdit.Text +
          ImagesLBX.Items[i] + '"></a>';
        i := i + 1;
      end
    until i = ImagesLBX.Count; {10th Dec 09 - removed -1}
  end
  else
  begin
    repeat
      begin
        SynMEMO1.Lines.Strings[i] := '<a href="' + BaseURLEdit.Text +
          BaseFolderEdit.Text + ImagesLBX.Items[i] + '" ' + 'rel="lightbox"' +
          '><img src="' + BaseURLEdit.Text + BaseFolderEdit.Text +
          ThumbsFolderEdit.Text + ThumbnailPrefixEdit.Text + ImagesLBX.Items[i] +
          '"></a>';
        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
« Last Edit: April 25, 2011, 09:10:35 am by misterkode »
It's not a bug...just an undocumented feature ;)
Carl Kruck :: www.graphicdreamz.net
Intel Core 2 Quad, 8Gb RAM, Nvidia Geforce GTX 260, Windows 7 HP SP1 64-Bit

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: Code works in TMemo but not TSynEditMemo (Exception)
« Reply #1 on: April 25, 2011, 10:35:19 am »
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 ?!)
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12296
  • Debugger - SynEdit - and more
    • wiki
Re: Code works in TMemo but not TSynEditMemo (Exception)
« Reply #2 on: April 25, 2011, 10:38:18 am »
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

  • New Member
  • *
  • Posts: 33
    • Stuff I like, yeh
Re: Code works in TMemo but not TSynEditMemo (Exception)
« Reply #3 on: April 25, 2011, 11:28:55 am »
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 ?!)

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
It's not a bug...just an undocumented feature ;)
Carl Kruck :: www.graphicdreamz.net
Intel Core 2 Quad, 8Gb RAM, Nvidia Geforce GTX 260, Windows 7 HP SP1 64-Bit

MisterKode

  • New Member
  • *
  • Posts: 33
    • Stuff I like, yeh
Re: Code works in TMemo but not TSynEditMemo (Exception)
« Reply #4 on: April 25, 2011, 11:41:52 am »
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



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
It's not a bug...just an undocumented feature ;)
Carl Kruck :: www.graphicdreamz.net
Intel Core 2 Quad, 8Gb RAM, Nvidia Geforce GTX 260, Windows 7 HP SP1 64-Bit

 

TinyPortal © 2005-2018