Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

End of lines in a richedit control

40 views
Skip to first unread message

David Pate

unread,
Dec 13, 2003, 11:47:16 PM12/13/03
to
How do I determine the maximum number of lines in the richedit control. I
load a text file to it, but a end of file apparently is not present. What I
want is how to determine what Jmax should be:
For J=1 to Jmax do
Begin
LineStatement := Richedit1.lines.strings[j];
do some things;
end;
Thanks,
David


Peter Below (TeamB)

unread,
Dec 14, 2003, 4:04:09 AM12/14/03
to

Typical off-by-one error. The indices for TRichedit.Lines are zero-based, not
one based. So your loop should look like

for J:= 1 to Richedit1.Lines.Count do begin
LineStatement := Richedit1.Lines[J - 1];
...
end;

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Henry B

unread,
Dec 14, 2003, 6:10:44 PM12/14/03
to
David Pate <dnpate(nospam)@mobis.com> wrote

David

Some time ago, I prepared a "canned answer" to questions of this
nature

The following remarks apply to the versions of Delphi that use the
Windows Richedit version 1 control. I understand that this includes
all Delphi versions prior to version 7. (I do not know what the
situation is when you run programs compiled in these versions on the
various NT/2000 versions of Windows although Windows XP behaves as
described.)

Q. What is the limit to the amount of text that a Richedit can hold?

A. The help files (Delphi help and Win32 SDK) are confusing,
contradictory and incorrect on this point.

There are 5 limits to be considered

1. The Maximum Capacity: the "hard-wired" limit, i.e the maximum size
of the RichEdit's text buffer.

It is 2 bytes less than 2 Gb.

Note that this is the theoretical limit; in practice the limit will
be determined by your computer's memory.

2. The Capacity: the actual size of the current buffer. By default, it
is 64Kb but can be resized by several means.

3. The "Keyboard limit": the limit beyond which characters cannot be
added by typing from the keyboard. It is often different from the
Capacity but, like the Capacity, it is by default, 64Kb and can be
resized by several means.

4. The MaxLength property of the tRichEdit object. The default of 0
sets both the Capacity and "Keyboard limit" to 64Kb.

5. The line-number limit: theoretically this is around 134 million,
but in practice, you can expect to get much less than this. The
maximum number of lines seems to depend on several factors
including the amount of memory available and the average length of
the lines. I find that I can get around 150 thousand to 200
thousand lines.

Note also that it has been reported that some releases of the
Windows 95 Richedit control sometimes throw an exception when more
than a few hundred lines are added. This appears to be due to a
bug in the control and to have been corrected in later releases..

Q. How can I increase the amount of text that a tRichEdit can hold?

A. When you add text programmatically, both the Capacity and the
"Keyboard limit" are resized to accommodate the text being added.
By adding text programmatically, I mean using any of the Add,
Append, AddStrings or Assign methods of the tRichEdit.Lines
property or the LoadFromFile, LoadFromStream or SetTextBuf methods
of tRichEdit. Note that adding text in this way does not update
the MaxLength property.

B. By using the MaxLength property. This sets the "Keyboard limit" to
the value passed to MaxLength. It also increases the Capacity to
match the "Keyboard limit" if the existing Capacity is less than
MaxLength.

Note that you cannot use MaxLength to reduce the Capacity and that
changing MaxLength has no effect if the value passed is less than
the length of the text currently in the control.

To increase the Capacity and the "Keyboard limit" to the same
value, set the tRichEdit.MaxLength to the desired value. To set the
maximum size in the Object Inspector, use the value 2147483645
($7FFFFFFD). To set it programmatically it is simpler to use
. MaxLength := System.MaxInt-2;.

The EM_LIMITTEXT and EM_EXLIMITTEXT messages may also be used to
change the "Keyboard limit" and Capacity but I would not normally
recommend using them since, if you do, you will not be updating the
MaxLength property.

--
Henry Bartlett

0 new messages