Board index » delphi » Problems saving memo text in stringlists.

Problems saving memo text in stringlists.

Hi All,

What would be the best way to store memo text in a stringlist?

I need to let my users makes notes etc in a memo field, using the cr/lf
but when they do and I save the contents of that and subsequent memos to
a stringlist the information goes all awry because the stringlist
recognises the cr/lf as the start of a new entry in the list.

I could do it other ways using different files for storage but I need
the delete function plus some of the other versatility of the
stringlist.  

Does anyone have any suggestions ?

Thanks,
Liam Healy

 

Re:Problems saving memo text in stringlists.


On Sun, 27 Oct 2002 17:58:52 +0000, "L. Healy"

Quote
<L.He...@occpsy.demon.co.uk> wrote:
>Hi All,

>What would be the best way to store memo text in a stringlist?

>I need to let my users makes notes etc in a memo field, using the cr/lf
>but when they do and I save the contents of that and subsequent memos to
>a stringlist the information goes all awry because the stringlist
>recognises the cr/lf as the start of a new entry in the list.

>I could do it other ways using different files for storage but I need
>the delete function plus some of the other versatility of the
>stringlist.  

>Does anyone have any suggestions ?

You could represent the line breaks using some sort of encoding when
you transfer the note text out of the TMemo.

Or how about using a collection (e.g. a TList) of StringLists, each of
which represents a note?

Stephen Posey
slpo...@concentric.net

Re:Problems saving memo text in stringlists.


In article <3dbc6cc3.3449...@news.concentric.net>, Stephen Posey
<slpo...@concentric.net> writes
Quote
>On Sun, 27 Oct 2002 17:58:52 +0000, "L. Healy"
><L.He...@occpsy.demon.co.uk> wrote:

>>Hi All,

>>What would be the best way to store memo text in a stringlist?

>>I need to let my users makes notes etc in a memo field, using the cr/lf
>>but when they do and I save the contents of that and subsequent memos to
>>a stringlist the information goes all awry because the stringlist
>>recognises the cr/lf as the start of a new entry in the list.

>>I could do it other ways using different files for storage but I need
>>the delete function plus some of the other versatility of the
>>stringlist.  

>>Does anyone have any suggestions ?

>You could represent the line breaks using some sort of encoding when
>you transfer the note text out of the TMemo.

>Or how about using a collection (e.g. a TList) of StringLists, each of
>which represents a note?

>Stephen Posey
>slpo...@concentric.net

Hi Stephen,

Do mean replacing the cr/lf with an arbitrary string which gets
translated back to cr/lf when read back in?
Liam Healy

Re:Problems saving memo text in stringlists.


Rather than using an arbitrary value, I replace them with "<BR>" when
saving to disk, and if putting back into a memo replace "<BR>" with
the CR/LF pair.

This way the contents of the memo can, if required, be put in an HTML
stream. It is then rendered exactly the same as the memo was,
including wrapping.

Julian Eriksen

Quote
"L. Healy" <L.He...@occpsy.demon.co.uk> wrote in message
> Do mean replacing the cr/lf with an arbitrary string which gets
> translated back to cr/lf when read back in?
> Liam Healy

Re:Problems saving memo text in stringlists.


Quote
"L. Healy" <L.He...@occpsy.demon.co.uk> wrote in message <news:HcqyRIAclCv9Ew0A@occpsy.demon.co.uk>...
> Hi All,

> What would be the best way to store memo text in a stringlist?

> I need to let my users makes notes etc in a memo field, using the cr/lf
> but when they do and I save the contents of that and subsequent memos to
> a stringlist the information goes all awry because the stringlist
> recognises the cr/lf as the start of a new entry in the list.

Hi Liam,

How about just adding the TMemo.Text to the stringlist.  My form has
three memos and inspecting the values of SL[0],sl[1] after executing

SL.Add( Memo1.Text);
SL.Add( Memo2.Text);

shows that the entries hold the full memo contents including #10#13's.
 This assumes you know which entry you want to delete at a later
stage.

A better idea might be to subclass the TStringList and overload the
add method something like the following little app.  It has two memos,
two buttons.  Add a memo1 with the first line being a unique
identifier (repeat a couple of times) and click button2 which fills
memo2 with the list of memos.  This has the advantage that
TMyStringList has all the nice delete/sorting methods (keyed on the
uniqueID).  Hope it might be of some use/give you some ideas.

Ed Barrett

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type TMyStringList=
class( TstringList)
    public
        procedure Add( aUniqueID: String;
                       aMemo:     TStrings); overload;
end;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Memo2: TMemo;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    SL: TMyStringList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TMyStringList.Add( aUniqueID: String;
                             aMemo: TStrings);
var aSL: TStringList;

begin
   aSL:= TStringList.Create;
   aSL.Assign( aMemo);

   AddObject( aUniqueID,
              aSL);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    SL:= TMyStringList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    SL.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    SL.Add( Memo1.Lines[1],
            Memo1.Lines);

    Memo1.Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);

var Index: Integer;

begin
    for Index:= 0 to ( SL.Count - 1) do
    begin
        Memo2.lines.Append( TStringList( SL.Objects[ Index]).Text);
    end;
end;

end.

Re:Problems saving memo text in stringlists.


Quote
Ed wrote in message <22f4bce8.0210280321.6a1af...@posting.google.com>...
>... #10#13 ...

ITYM #13#10.

Groetjes,
Maarten Wiltink

Re:Problems saving memo text in stringlists.


Im Artikel <HcqyRIAclCv9E...@occpsy.demon.co.uk>, "L. Healy"
<L.He...@occpsy.demon.co.uk> schreibt:

Quote
>I need to let my users makes notes etc in a memo field, using the cr/lf
>but when they do and I save the contents of that and subsequent memos to
>a stringlist the information goes all awry because the stringlist
>recognises the cr/lf as the start of a new entry in the list.

This is the intended behaviour of a stringlist. Use something like
stringlist.Add(memo.Text) if the text should become a single entry in the
stringlist.

DoDi

Re:Problems saving memo text in stringlists.


On Sun, 27 Oct 2002 17:58:52 +0000, "L. Healy"

Quote
<L.He...@occpsy.demon.co.uk> wrote:
> Hi All,

> What would be the best way to store memo text in a stringlist?

  MyStringList.Assign(Memo1.Lines);

--
Rudy Velthuis

Re:Problems saving memo text in stringlists.


On Sun, 03 Nov 2002 14:47:49 +0100, Rudy Velthuis <rvelth...@gmx.de>
wrote:

Quote
>On Sun, 27 Oct 2002 17:58:52 +0000, "L. Healy"
><L.He...@occpsy.demon.co.uk> wrote:

>> Hi All,

>> What would be the best way to store memo text in a stringlist?

>  MyStringList.Assign(Memo1.Lines);

I dont think so, Liam wants the entire Memo to just be *one* line in
the TStringList

The use of <BR> to replace CrLf is one viable method

Actually he might be wise to look at TIniFile as a storage medium, not
the inbuilt ones from Delphi, but a roll your own version, which is
quite simple to do.

The Memo could be an entire section.

Quote

>--
>Rudy Velthuis

Re:Problems saving memo text in stringlists.


In article <3dc5e709.1513...@news.u-net.com>, J French
<Bounce_It_je...@iss.u-net.com_.bin> writes
Quote
>On Sun, 03 Nov 2002 14:47:49 +0100, Rudy Velthuis <rvelth...@gmx.de>
>wrote:

>>On Sun, 27 Oct 2002 17:58:52 +0000, "L. Healy"
>><L.He...@occpsy.demon.co.uk> wrote:

>>> Hi All,

>>> What would be the best way to store memo text in a stringlist?

>>  MyStringList.Assign(Memo1.Lines);
>I dont think so, Liam wants the entire Memo to just be *one* line in
>the TStringList

>The use of <BR> to replace CrLf is one viable method

>Actually he might be wise to look at TIniFile as a storage medium, not
>the inbuilt ones from Delphi, but a roll your own version, which is
>quite simple to do.

>The Memo could be an entire section.

Hi,

Jerry is right. But thanks for the suggestion. I got it sorted and
posted the solution under a new thread but it might not have made it.
But this was it :

===========

Thanks All, for all your help, this was what I finally did, I'm posting
it out of politeness, I know it is ugly and there will better ways of
doing it, but you have to work within your competence. I found
comparedate and worked out how to use that.

The rest is mainly based on Alan's stuff plus some stuff he posted a
while ago. It works, I have yet to see what the problems are though!

procedure TFormMain.ButtonProduceDiaryReportClick(Sender: TObject);

var
DatePosI, DeleteRowI, DiaryReportI  : integer;
DiarySorted : boolean;

begin
         //delete the empty rows, count backwards in
         For  DeleteRowI := StringGridDiary.RowCount - 1 downto 1 do

             begin
                     If ((StringGridDiary.Cells[0,DeleteRowI] = '')
                        and (StringGridDiary.Cells[1,DeleteRowI] = '')
                            and (StringGridDiary.Cells[2,DeleteRowI] =
''))
                     then
                     begin
                     TChangeGrid (StringGridDiary).DeleteRow
(DeleteRowI);
                     end;
             end;

begin //now sort out what is left by date order
            Repeat
            DiarySorted := true;
            For DatePosI := 1 to StringGridDiary.RowCount - 1 do

            If (StringGridDiary.Cells[0,DatePosI] <> '') and (StringGrid
Diary.Cells[0,DatePosI+1] <> '')  then

            begin
               If CompareDate((StrToDate(StringGridDiary.Cells[0,DatePos
I])),(StrToDate(StringGridDiary.Cells[0,DatePosI+1]))) = 1 then
                  begin
                  TMoveRowSG(StringGridDiary).MoveRow(DatePosI + 1,
DatePosI);
                  DiarySorted := false;
                  end;
               end;

            until DiarySorted;

end;
Liam Healy

Other Threads