Discussion:
RichEdit line insertion error
(too old to reply)
Stark
2010-03-27 20:14:25 UTC
Permalink
I am retrieving text form a file .rtf. I am using two different expressions
in two different path in my program. These are the statements:

1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text content
directly into MemoGen which is a TRichEdit
//
This is OK !

2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content into
aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit. !!
HERE I GET THE ERROR !!!

At runtime, going step by step, I can see that the string which is loaded
directly into the RichEdit and the one loaded into the StringList come with
a different format.
The first starts with: #$D#$A' ......... (dots are the original
string Text)

The second starts with: {\rtf\ansi------------------------}--#SD#$A'\par
......text.........

The error I get states: "raised exception class EOutOfResources with message
'RichEdit line insertion error'"

The reason I go through the TStringList is that I created an object where
the text of the file memo.rtf is one of the properties from which a RichEdit
may be loaded...

I hope I've been clear enough. The question is: is there something I can do
? Am i making a mistake or should I change solution or what ?
Jamie
2010-03-27 22:11:59 UTC
Permalink
Post by Stark
I am retrieving text form a file .rtf. I am using two different
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text
content directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit.
!! HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is
loaded directly into the RichEdit and the one loaded into the StringList
come with a different format.
The first starts with: #$D#$A' ......... (dots are the
original string Text)
{\rtf\ansi------------------------}--#SD#$A'\par ......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object
where the text of the file memo.rtf is one of the properties from which
a RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I can
do ? Am i making a mistake or should I change solution or what ?
I don't understand why you should be getting an error? unless how ever,
you are using an object that isn't created?

It's possible there is an implementation error with the TRichedit..
the "ADD" method of the TStrings may not be implemented. Setting the
"Text" property executes the "ADD".

The Lines property uses the "TStrings" which is an abstract class.
This means that it's possible not all methods are implemented or there
maybe an error..

The TRichEdit is a wrapper class for a windows control "ActiveX",
hard to say where the error is coming from.

Make sure you are creating both objects before using them and instead
of using the Text property of lines, try using a "Assign"
Lines.Assign(aMemo);
Stark
2010-03-27 23:10:45 UTC
Permalink
Sorry for the message in italian, but I wrote my problem in my language ,
then translated it and by mistake sent both messages.
Anyway, I made a small test program with a form with two RichEdits and two
buttons. All of the program is here:

procedure TForm1.Button1Click(Sender: TObject);
begin
RE1.Lines.LoadFromFile(PathDB+'Memo.rtf'); // THIS IS OK
end;

procedure TForm1.Button2Click(Sender: TObject);
var
aMemoText: TStrings;
begin
aMemoText:= TStringList.Create;
aMemoText.LoadFromFile(PathDB+'Memo.rtf');
RE2.Lines.Text:= aMemoText.Text; //HERE I GET RichEdit line insertion
error
end;
I added a TMemo on the form and this line to Button2Click:
Memo1.Text:= aMemoText.Text;

It does work and show in the memo the following string
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil
Tahoma;}{\f1\fnil\fcharset0 Tahoma;}}
\viewkind4\uc1\pard\f0\fs16
\par THIS IS MY TEXT

So, since memo,rtf is the source for both procedure, it looks that it's
what gets inside the TStrings is different from what gets inside the
richEdit. I don't know what to think..
Post by Jamie
Post by Stark
I am retrieving text form a file .rtf. I am using two different
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text content
directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit.
!! HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is loaded
directly into the RichEdit and the one loaded into the StringList come
with a different format.
The first starts with: #$D#$A' ......... (dots are the
original string Text)
{\rtf\ansi------------------------}--#SD#$A'\par ......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object where
the text of the file memo.rtf is one of the properties from which a
RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I can
do ? Am i making a mistake or should I change solution or what ?
I don't understand why you should be getting an error? unless how ever,
you are using an object that isn't created?
It's possible there is an implementation error with the TRichedit..
the "ADD" method of the TStrings may not be implemented. Setting the
"Text" property executes the "ADD".
The Lines property uses the "TStrings" which is an abstract class. This
means that it's possible not all methods are implemented or there maybe an
error..
The TRichEdit is a wrapper class for a windows control "ActiveX", hard
to say where the error is coming from.
Make sure you are creating both objects before using them and instead of
using the Text property of lines, try using a "Assign"
Lines.Assign(aMemo);
Jamie
2010-03-28 04:33:52 UTC
Permalink
Post by Stark
Sorry for the message in italian, but I wrote my problem in my language
, then translated it and by mistake sent both messages.
Anyway, I made a small test program with a form with two RichEdits and
procedure TForm1.Button1Click(Sender: TObject);
begin
RE1.Lines.LoadFromFile(PathDB+'Memo.rtf'); // THIS IS OK
end;
procedure TForm1.Button2Click(Sender: TObject);
var
aMemoText: TStrings;
begin
aMemoText:= TStringList.Create;
aMemoText.LoadFromFile(PathDB+'Memo.rtf');
RE2.Lines.Text:= aMemoText.Text; //HERE I GET RichEdit line insertion
error
end;
Memo1.Text:= aMemoText.Text;
It does work and show in the memo the following string
{\rtf1\ansi\ansicpg1252\deff0\deflang1040{\fonttbl{\f0\fnil
Tahoma;}{\f1\fnil\fcharset0 Tahoma;}}
\viewkind4\uc1\pard\f0\fs16
\par THIS IS MY TEXT
So, since memo,rtf is the source for both procedure, it looks that it's
what gets inside the TStrings is different from what gets inside the
richEdit. I don't know what to think..
You can not use Tstrings directly!...

It is a "ABtract" Class and reserved for building classes from it..

Many of the functions do not work in Abtract classes.

Please use "TStringList" in it's place.

Var
AMemoText:TStringList;
Begin
aMemoText := Tstringlist.Create;

//also try this instead..

...

RE2.Lines.Assign(aMemoText);
Maarten Wiltink
2010-03-28 12:46:53 UTC
Permalink
Post by Jamie
Post by Stark
var
aMemoText: TStrings;
begin
aMemoText:= TStringList.Create;
[...]
Post by Jamie
You can not use Tstrings directly!...
He doesn't. He clearly instantiates TStringList, not TStrings.


[...]
Post by Jamie
Please use "TStringList" in it's place.
Var
AMemoText:TStringList;
Begin
aMemoText := Tstringlist.Create;
DON'T DO THAT.

I recently (the 12th of this last month) wrote a fairly long article
about exactly that, right here.

http://groups.google.com/groups/search?as_umsgid=4b9aa9f9%240%2422937%24e4fe514c%40news.xs4all.nl&hl=en

Groetjes,
Maarten Wiltink
Stark
2010-03-29 11:17:49 UTC
Permalink
I am using TStringList.
Maarten, can you explain your "DON'T DO THAT" ? What'is that I shouldn't do
? Your link takes me to this messages in Internet and I can't see the
article you mention..
Post by Maarten Wiltink
Post by Jamie
Post by Stark
var
aMemoText: TStrings;
begin
aMemoText:= TStringList.Create;
[...]
Post by Jamie
You can not use Tstrings directly!...
He doesn't. He clearly instantiates TStringList, not TStrings.
[...]
Post by Jamie
Please use "TStringList" in it's place.
Var
AMemoText:TStringList;
Begin
aMemoText := Tstringlist.Create;
DON'T DO THAT.
I recently (the 12th of this last month) wrote a fairly long article
about exactly that, right here.
http://groups.google.com/groups/search?as_umsgid=4b9aa9f9%240%2422937%24e4fe514c%40news.xs4all.nl&hl=en
Groetjes,
Maarten Wiltink
Maarten Wiltink
2010-03-29 11:58:15 UTC
Permalink
Post by Stark
I am using TStringList.
Maarten, can you explain your "DON'T DO THAT" ? What'is that I
shouldn't do ? Your link takes me to this messages in Internet and I
can't see the article you mention..
Try this. news:4b9aa9f9$0$22937$***@news.xs4all.nl

If that doesn't work either, goto Google Groups, Advanced Search, Look
up the message with message ID, and paste the above message id (the part
after 'news:').

Groetjes,
Maarten Wiltink
BRoberts
2010-03-30 16:44:05 UTC
Permalink
Post by Stark
I am retrieving text form a file .rtf. I am using two different expressions
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text content
directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit. !!
HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is loaded
directly into the RichEdit and the one loaded into the StringList come
with a different format.
The first starts with: #$D#$A' ......... (dots are the original
string Text)
{\rtf\ansi------------------------}--#SD#$A'\par ......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object where
the text of the file memo.rtf is one of the properties from which a
RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I can
do ? Am i making a mistake or should I change solution or what ?
If your intent is to assign formatted text then what you are doing will not
work, regardless of the current error. The only mechanisms I've found that
loads formatted text into a rich edit the to use it's LoadFromStream or
LoadFromFile methods. In your case you can use LoadFromStream. You might
want to look at tStringStream or tMemoryStream.

As to the error, is it possible that the text amount is large and you have
not set the tRichEdit.MaxLength property?
Stark
2010-03-31 09:36:28 UTC
Permalink
MaxLength is set to 0.
My objective is to retrieve the text that the user types into a richEdit
panel, save it in a file (in this case is a Memo field in a dBase dataset).
This same text should be loaded from this file and kept in a TStrings type
(TStringList) property of an object which may be asked to show it again in a
RichEdit.
Post by BRoberts
Post by Stark
I am retrieving text form a file .rtf. I am using two different
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text content
directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit.
!! HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is loaded
directly into the RichEdit and the one loaded into the StringList come
with a different format.
The first starts with: #$D#$A' ......... (dots are the
original string Text)
The second starts with: {\rtf\ansi------------------------}--#SD#$A'\par
......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object where
the text of the file memo.rtf is one of the properties from which a
RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I can
do ? Am i making a mistake or should I change solution or what ?
If your intent is to assign formatted text then what you are doing will
not work, regardless of the current error. The only mechanisms I've found
that loads formatted text into a rich edit the to use it's LoadFromStream
or LoadFromFile methods. In your case you can use LoadFromStream. You
might want to look at tStringStream or tMemoryStream.
As to the error, is it possible that the text amount is large and you have
not set the tRichEdit.MaxLength property?
BRoberts
2010-04-01 04:24:20 UTC
Permalink
Post by Stark
MaxLength is set to 0.
My objective is to retrieve the text that the user types into a richEdit
panel, save it in a file (in this case is a Memo field in a dBase dataset).
This same text should be loaded from this file and kept in a TStrings type
(TStringList) property of an object which may be asked to show it again in
a RichEdit.
Post by BRoberts
Post by Stark
I am retrieving text form a file .rtf. I am using two different
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text
content directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit.
!! HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is
loaded directly into the RichEdit and the one loaded into the StringList
come with a different format.
The first starts with: #$D#$A' ......... (dots are the
original string Text)
The second starts with: {\rtf\ansi------------------------}--#SD#$A'\par
......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object
where the text of the file memo.rtf is one of the properties from which
a RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I can
do ? Am i making a mistake or should I change solution or what ?
If your intent is to assign formatted text then what you are doing will
not work, regardless of the current error. The only mechanisms I've found
that loads formatted text into a rich edit the to use it's LoadFromStream
or LoadFromFile methods. In your case you can use LoadFromStream. You
might want to look at tStringStream or tMemoryStream.
As to the error, is it possible that the text amount is large and you
have not set the tRichEdit.MaxLength property?
Please don't top post.

You need to set MaxLength to an appropriately large number. My memory is
hazy but I seem to recall that the default length is rather small, 8 or 16 K
is IIRC.

Unless the originating rich edit, i.e. the one storing the text, has its
PlainText property set True I'd suggest that you change the property type of
the object storing the text to tMemoryStream. That way you can load the data
into a rich edit using it's LoadFromStream method. tMemoryStream has a
LoadFromFile method which will facilitate loading the text. Just remember to
set the stream's Position property to zero after executing the method.
Stark
2010-04-01 08:20:24 UTC
Permalink
Thanks for your help. I will try your suggestion.
PS: I am receiving advice of not top-posting by a few people. I don't know
what to do. I DO NOT "top post" and it doesn't look I do if I look at my
forum messages tree ...
Post by BRoberts
Post by Stark
MaxLength is set to 0.
My objective is to retrieve the text that the user types into a richEdit
panel, save it in a file (in this case is a Memo field in a dBase dataset).
This same text should be loaded from this file and kept in a TStrings
type (TStringList) property of an object which may be asked to show it
again in a RichEdit.
Post by BRoberts
Post by Stark
I am retrieving text form a file .rtf. I am using two different
1 - MemoGen.Lines.LoadFromFile('memo.rtf'); // loading the text
content directly into MemoGen which is a TRichEdit
// This is OK !
2 - aMemo.LoadFromFile('memo.rtf'); // loading the text content
into aMemo which is a TStringList
MemoGen.Lines.Text:= aMemo.Text; // and then into the richEdit.
!! HERE I GET THE ERROR !!!
At runtime, going step by step, I can see that the string which is
loaded directly into the RichEdit and the one loaded into the
StringList come with a different format.
The first starts with: #$D#$A' ......... (dots are the
original string Text)
{\rtf\ansi------------------------}--#SD#$A'\par ......text.........
The error I get states: "raised exception class EOutOfResources with
message 'RichEdit line insertion error'"
The reason I go through the TStringList is that I created an object
where the text of the file memo.rtf is one of the properties from which
a RichEdit may be loaded...
I hope I've been clear enough. The question is: is there something I
can do ? Am i making a mistake or should I change solution or what ?
If your intent is to assign formatted text then what you are doing will
not work, regardless of the current error. The only mechanisms I've
found that loads formatted text into a rich edit the to use it's
LoadFromStream or LoadFromFile methods. In your case you can use
LoadFromStream. You might want to look at tStringStream or
tMemoryStream.
As to the error, is it possible that the text amount is large and you
have not set the tRichEdit.MaxLength property?
Please don't top post.
You need to set MaxLength to an appropriately large number. My memory is
hazy but I seem to recall that the default length is rather small, 8 or 16
K is IIRC.
Unless the originating rich edit, i.e. the one storing the text, has its
PlainText property set True I'd suggest that you change the property type
of the object storing the text to tMemoryStream. That way you can load the
data into a rich edit using it's LoadFromStream method. tMemoryStream has
a LoadFromFile method which will facilitate loading the text. Just
remember to set the stream's Position property to zero after executing the
method.
Maarten Wiltink
2010-04-01 10:49:12 UTC
Permalink
"Stark" <***@tin.it> wrote in message news:4bb45746$1$824$***@reader5.news.tin.it...

TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT
DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES
NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT
GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO
HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE. TEXT DOES NOT GO HERE.


[...]
Post by Stark
PS: I am receiving advice of not top-posting by a few people. I don't
know what to do. I DO NOT "top post" and it doesn't look I do if I look
at my forum messages tree ...
YES YOU DO.

Top- or bottom-posting applies _within_ a message.

On one hand, I'm pleased you haven't given up on the subject yet, on the
other, I hope you're better at more conventional intelligence tests.

(No, this is what I look like when I _am_ doing my best not to insult you.)

Groetjes,
Maarten Wiltink
Rudy Velthuis
2010-04-01 18:06:13 UTC
Permalink
Post by Stark
Thanks for your help. I will try your suggestion.
PS: I am receiving advice of not top-posting by a few people. I don't
know what to do. I DO NOT "top post"
YES, YOU DO! Your reply is at the top of the message and that is called
"top posting". The fact that you don't cut most of the quotes beneath
it doesn't improve things either. Some newsreaders, like MS Outlook
Express and MS Mail proimote this, but it is not good.

http://rvelthuis.de/articles/articles-quoting.html

IOW, you committed two "sins":

- you added your reply at the very top of the message. That is called
"top posting" and is considered bad and illgical by many.

- you quoted everything from the previous message, which means your
message contained 82 lines of text, of which only three (3) were new.
The rest was quoted from other messages. That is called "overquoting",
and in your case, in a rather extreme form. That is another (IMO even
worse) "sin" in newsgroups.

FWIW, note that "underquoting" (or not quoting at all) is almost as bad
as "overquoting".
--
Rudy Velthuis http://rvelthuis.de

"Despite the high cost of living, it remains popular."
Stark
2010-04-02 08:52:26 UTC
Permalink
Post by Rudy Velthuis
Post by Stark
Thanks for your help. I will try your suggestion.
PS: I am receiving advice of not top-posting by a few people. I don't
know what to do. I DO NOT "top post"
YES, YOU DO! Your reply is at the top of the message and that is called
"top posting". The fact that you don't cut most of the quotes beneath
it doesn't improve things either. Some newsreaders, like MS Outlook
Express and MS Mail proimote this, but it is not good.
http://rvelthuis.de/articles/articles-quoting.html
- you added your reply at the very top of the message. That is called
"top posting" and is considered bad and illgical by many.
- you quoted everything from the previous message, which means your
message contained 82 lines of text, of which only three (3) were new.
The rest was quoted from other messages. That is called "overquoting",
and in your case, in a rather extreme form. That is another (IMO even
worse) "sin" in newsgroups.
FWIW, note that "underquoting" (or not quoting at all) is almost as bad
as "overquoting".
--
Rudy Velthuis http://rvelthuis.de
"Despite the high cost of living, it remains popular."
You are the first one that just doesn't tell mee abrubtly not to toppost,
but that explains what this means. I just inserted my test where the cursor
was flashing.. My excuses to everyone. I am guilty, but I din't know what my
sin was until now !!!
Rudy Velthuis
2010-04-02 15:42:22 UTC
Permalink
Post by Stark
Post by Rudy Velthuis
- you added your reply at the very top of the message.
- you quoted everything from the previous message
You are the first one that just doesn't tell mee abrubtly not to
toppost, but that explains what this means. I just inserted my test
where the cursor was flashing.. My excuses to everyone. I am guilty,
but I din't know what my sin was until now !!!
That is much better, but now you should work on reducing the quotes
(the text with the > in front). Reduce them to just enough to make
other follow the thread (see above - just enough to give you a hint
what I'm tlaking about). At the moment, you are still overquoting.

And also don't quote the signature, that is the stuff below the "-- "
line.
--
Rudy Velthuis http://rvelthuis.de

"You're bound to be unhappy if you optimize everything."
-- Donald Knuth
Loading...