Board index » delphi » TMemo / TRichEdit Q's....

TMemo / TRichEdit Q's....

Hi everyone,

I'm writing a text editor ('cos hey, the world doesn't have
enough already...) and am deciding between a TMemo or a
TRichEdit.

I am *only* doing text editing, not formatting and don't
need the extra Rich text capabilities of the Rich Edit, but
I have noticed that:

 - TMemo seemed to have a limit in the size of files it
could load

 - TRichEdit has it's own findtext function (ok, I could
write my own - I already wrote my own find / replace dialog,
so hey, why not - but as long as I'm listing advantages /
disadvantages)

I want to be able to have the ability to load really big
files, without taking *too* long to do it is I guess my
biggest thing that I want, although I'd also like to be able
to highlight (say, by turning blue and underlining) URL's
which could be double clicked to execute in a browser.

What are the differences between the two types of edit box
in order to do this?

Also, what is the fastest way to load files into one of
these.

I've got a TRichEdit at the moment and tried loading a
fairly big (2mb) file with it's TRichEdit.Lines.loadFromFile
function, and I'm not sure if it was doing it or not, I
reset it after awhile.

I wrote a routine to do it and discovered that:

my routine can open the file and put all the strings into a
StringList in a couple of seconds, but I can't find a way to
get them into the RichEdit that works:

I've tried:

RichEdit.text := stringlist.text;
richedit.addstrings(stringlist.strings)
going through copying each line individually.
I can't remember what else.

So what is the best way to 'manually' load this file?  
(assuming there is a better way than the Richedit's
loadfromfile function...

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

 

Re:TMemo / TRichEdit Q's....


TRichEdit will be better if only for the fact that you can store a lot more
text into it: Set the plaintext property to true and set the "Maxlength"
property to a suitably large number, such as 2147483645. Although you could
make blue and underline hyperlinks in the RichEdit, there is no built in
function to have text that you can click on; You could try looking on a
Delphi component site (Like Torrys) for a RichEdit with hyperlink
capability. I don't know how to solve your slow loading dilemma - if
RichEdit has beginupdate/endupdate methods you could try:

1. Call beginupdate
2. Loading it in yourself, one line at a time
3. Call endupdate

Cheers,
Nicholas Sherlock

Quote
"OgO" <quent...@qjc.cjbGlasses.net> wrote in message

news:Xns92A2CCCD313Dogo1mynxwowaustcom@210.49.20.254...
Quote
> Hi everyone,

> I'm writing a text editor ('cos hey, the world doesn't have
> enough already...) and am deciding between a TMemo or a
> TRichEdit.

> I am *only* doing text editing, not formatting and don't
> need the extra Rich text capabilities of the Rich Edit, but
> I have noticed that:

>  - TMemo seemed to have a limit in the size of files it
> could load

>  - TRichEdit has it's own findtext function (ok, I could
> write my own - I already wrote my own find / replace dialog,
> so hey, why not - but as long as I'm listing advantages /
> disadvantages)

> I want to be able to have the ability to load really big
> files, without taking *too* long to do it is I guess my
> biggest thing that I want, although I'd also like to be able
> to highlight (say, by turning blue and underlining) URL's
> which could be double clicked to execute in a browser.

> What are the differences between the two types of edit box
> in order to do this?

> Also, what is the fastest way to load files into one of
> these.

> I've got a TRichEdit at the moment and tried loading a
> fairly big (2mb) file with it's TRichEdit.Lines.loadFromFile
> function, and I'm not sure if it was doing it or not, I
> reset it after awhile.

> I wrote a routine to do it and discovered that:

> my routine can open the file and put all the strings into a
> StringList in a couple of seconds, but I can't find a way to
> get them into the RichEdit that works:

> I've tried:

> RichEdit.text := stringlist.text;
> richedit.addstrings(stringlist.strings)
> going through copying each line individually.
> I can't remember what else.

> So what is the best way to 'manually' load this file?
> (assuming there is a better way than the Richedit's
> loadfromfile function...

> Regards

> OgO
> --
> My Freeware: http://qjc.cjb.net/freeware.html
> My Win9x Cursors: http://qjc.cjb.net/cursors.html
> ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
> I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


Quote
On Thu, 10 Oct 2002 07:38:23 +1300, Nicholas Sherlock wrote:
> TRichEdit will be better if only for the fact that you can store a lot more
> text into it: Set the plaintext property to true and set the "Maxlength"
> property to a suitably large number, such as 2147483645.

 ISTR that you can set the Maxlength property to -2 and get the same effect.

 --
 gbb

Re:TMemo / TRichEdit Q's....


Slow loading is easily solved by loading one page at a time. Make a
copy of the original file to a temporary file. Now, only read 1600
bytes or so at a time and display it on screen. When the users scrolls
to a new line or page, load the new 1600 bytes. When the user makes
changes, save the changes in realtime to the temporary file. When the
users saves the file, overwrite the original file with the temporary
file. This method involves a lot of disk access, but it avoids having
to load large files into memory.
-- Ravon
Quote
"Nicholas Sherlock" <n_sherl...@hotmail.com> wrote in message <news:ao1t3d$sip$1@lust.ihug.co.nz>...
> TRichEdit will be better if only for the fact that you can store a lot more
> text into it: Set the plaintext property to true and set the "Maxlength"
> property to a suitably large number, such as 2147483645. Although you could
> make blue and underline hyperlinks in the RichEdit, there is no built in
> function to have text that you can click on; You could try looking on a
> Delphi component site (Like Torrys) for a RichEdit with hyperlink
> capability. I don't know how to solve your slow loading dilemma - if
> RichEdit has beginupdate/endupdate methods you could try:

> 1. Call beginupdate
> 2. Loading it in yourself, one line at a time
> 3. Call endupdate

> Cheers,
> Nicholas Sherlock

> "OgO" <quent...@qjc.cjbGlasses.net> wrote in message
> news:Xns92A2CCCD313Dogo1mynxwowaustcom@210.49.20.254...
> > Hi everyone,

> > I'm writing a text editor ('cos hey, the world doesn't have
> > enough already...) and am deciding between a TMemo or a
> > TRichEdit.

> > I am *only* doing text editing, not formatting and don't
> > need the extra Rich text capabilities of the Rich Edit, but
> > I have noticed that:

> >  - TMemo seemed to have a limit in the size of files it
> > could load

> >  - TRichEdit has it's own findtext function (ok, I could
> > write my own - I already wrote my own find / replace dialog,
> > so hey, why not - but as long as I'm listing advantages /
> > disadvantages)

> > I want to be able to have the ability to load really big
> > files, without taking *too* long to do it is I guess my
> > biggest thing that I want, although I'd also like to be able
> > to highlight (say, by turning blue and underlining) URL's
> > which could be double clicked to execute in a browser.

> > What are the differences between the two types of edit box
> > in order to do this?

> > Also, what is the fastest way to load files into one of
> > these.

> > I've got a TRichEdit at the moment and tried loading a
> > fairly big (2mb) file with it's TRichEdit.Lines.loadFromFile
> > function, and I'm not sure if it was doing it or not, I
> > reset it after awhile.

> > I wrote a routine to do it and discovered that:

> > my routine can open the file and put all the strings into a
> > StringList in a couple of seconds, but I can't find a way to
> > get them into the RichEdit that works:

> > I've tried:

> > RichEdit.text := stringlist.text;
> > richedit.addstrings(stringlist.strings)
> > going through copying each line individually.
> > I can't remember what else.

> > So what is the best way to 'manually' load this file?
> > (assuming there is a better way than the Richedit's
> > loadfromfile function...

> > Regards

> > OgO
> > --
> > My Freeware: http://qjc.cjb.net/freeware.html
> > My Win9x Cursors: http://qjc.cjb.net/cursors.html
> > ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
> > I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


In comp.lang.pascal.delphi.misc, on 10 Oct 2002, Nicholas
Sherlock announced:

Quote
> TRichEdit will be better if only for the fact that you can
> store a lot more text into it: Set the plaintext property
> to true and set the "Maxlength" property to a suitably
> large number, such as 2147483645.

you don't actually *need* to set the MaxLength property.  So
far I've just left it at the default - 0, and that works ok
- from the help:

"Use MaxLength to limit the number of characters that can be
entered into the edit control. A value of 0 indicates that
there is no application-defined limit on the length."

The only time the program would *not* attempt to load a
large file was when I tried a TMemo and the program said it
was too big to fit in memory and didn't even try loading it.

Quote
> Although you could make
> blue and underline hyperlinks in the RichEdit, there is no
> built in function to have text that you can click on;

Yeah, I'll have to do that myself, but I have a few ideas of
how to do it, I'll probably let you all know when I get
stuck :)

Quote
> ...I don't know how
> to solve your slow loading dilemma - if RichEdit has
> beginupdate/endupdate methods you could try:

> 1. Call beginupdate
> 2. Loading it in yourself, one line at a time
> 3. Call endupdate

Yeah, I've tried that, also tried setting the edit to hide /
show etc, to no avail :(  Well - I know it *does* work
faster if it's not updating the display each time it adds a
line, but it's still painfully slow on anything of a
reasonable size.

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


In comp.lang.pascal.delphi.misc, on 10 Oct 2002, Ravon
announced:

Quote
> Slow loading is easily solved by loading one page at a
> time. Make a copy of the original file to a temporary
> file. Now, only read 1600 bytes or so at a time and
> display it on screen. When the users scrolls to a new line
> or page, load the new 1600 bytes.....

That's an awful lot of work and seems very messy.  It *is* one
way of doing it, but surely there is a better way?

I can read the file in to a TStringlist very quickly, but then
it takes forever transferring the data across to the edit.lines,
however I seem to do it.

To read the file I am doing:

var
   F:textfile;
   line, filename:string;
   lines:tstringlist;
begin
        ....

     AssignFile(F, filename);
     Reset(F);
     lines:=TStringList.create;
     while not eof(f) do
     begin
          readLn(f, line);
          lines.add(line);
     end;
     closefile(f);

That is completed - even on a 2MB file, in a couple of seconds.  

If I try and load say an 18KB file (the source of the form in
fact) into the program, loading it into the TRichEdit takes
about 10 seconds, after it has taken about a second to read it
into the stringlist.

If I change the lines.add line to read:

        Edit.Lines.Add(line);

where 'Edit' is my TRichEdit, the program takes the same amount
of time as it did before, the problem is with the RichEdit, and
I'm not sure why or how to fix it...

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


Quote
> you don't actually *need* to set the MaxLength property.  So
> far I've just left it at the default - 0, and that works ok
> - from the help:

> "Use MaxLength to limit the number of characters that can be
> entered into the edit control. A value of 0 indicates that
> there is no application-defined limit on the length."

> The only time the program would *not* attempt to load a
> large file was when I tried a TMemo and the program said it
> was too big to fit in memory and didn't even try loading it.

The help is incomplete - setting MaxLength to 0 just makes the maxlength
default to the default length of that OS, either 64k or 32k.

Cheers,
Nicholas Sherlock

Re:TMemo / TRichEdit Q's....


Quote
"OgO" <quent...@qjc.cjbGlasses.net> wrote in message
> you don't actually *need* to set the MaxLength property.  So
> far I've just left it at the default - 0, and that works ok
> - from the help:

In fact you do, if you want to work with files larger than 64KB (depending
on the particular o/s).

Re:TMemo / TRichEdit Q's....


Quote
"OgO" <quent...@qjc.cjbGlasses.net> wrote in message
> That's an awful lot of work and seems very messy.  It *is* one
> way of doing it, but surely there is a better way?

Agreed.

Quote
> I can read the file in to a TStringlist very quickly, but then
> it takes forever transferring the data across to the edit.lines,
> however I seem to do it.

As another poster suggested, you might try using the BeginUpdate method of
tStrings.

aRichEdit.PlainText := True;
aRichEdit.Lines.BeginUpdate;
try
    aRichEdit.Lines.LoadFromFile (theFilename);
finally
    aRichEdit.Lines.EndUpdate;
    end;

Another other option is

sl := tStringList.Create;
try
    sl.LoadFromFile (theFilename);
    aRichEdit.Text := sl.Text; // or aRichEdit.Lines.Assign (sl);
finally
    sl.Free;
    end;

Re:TMemo / TRichEdit Q's....


In comp.lang.pascal.delphi.misc, on 10 Oct 2002, Nicholas
Sherlock announced:

Quote
>> "Use MaxLength to limit the number of characters that can
>> be entered into the edit control. A value of 0 indicates
>> that there is no application-defined limit on the
>> length."

> The help is incomplete - setting MaxLength to 0 just makes
> the maxlength default to the default length of that OS,
> either 64k or 32k.

Oh ok, but when I had MaxLength set to 0, the program did
still try to load my 2MB file, and I don't know, if I'd left
it however long, 5 mins, an hour, 2.... it might have loaded
it, but thanks, I'll try changing it just to make sure.

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


If you are getting the data file into a TStringList very rapidly, then
the problem is not with file access
(although your later posting shows that you are using a very slow
method)

Are you sure that RichEdit1.Text := StringList.Text  is working very
slowly,
- and have you turned on the PlainText flag ?

Personally I agree with Ravon's point, that for very large files you
should keep them on disk.

This is not particularly difficult - one reads the file and 'indexes'
the start of each line - and (optionally) its length.
The reading does not have to be complete to get a snappy response.

By playing around with the index you can insert/delete lines

- this is probably best done by producing a 'virtual StringList' class

If you want highlighting then you will not (AFAIK) be able to use a
TMemo.  
The TRichEdit will do that for you - with some work - but you might be
better off thinking about painting your own lines.

If you do not want wordwrap, have you considered a huge Listbox for
display
- using UserDraw and a 'floating' Edit box.

On 09 Oct 2002 10:07:57 GMT, OgO <quent...@qjc.cjbGlasses.net> wrote:

Quote
>Hi everyone,

>I'm writing a text editor ('cos hey, the world doesn't have
>enough already...) and am deciding between a TMemo or a
>TRichEdit.

<snip>

Re:TMemo / TRichEdit Q's....


In comp.lang.pascal.delphi.misc, on 10 Oct 2002, J French
announced:

Quote
> If you are getting the data file into a TStringList very
> rapidly, then the problem is not with file access
> (although your later posting shows that you are using a
> very slow method)

Yeah that reading it in, was just one way I tried - I tried
a lot of things to see what worked, what worked quicker,
etc.

Ok, I found that a lot of the problem was caused by my
routine which updated the statusbar with information about
the file (col x/y line x/y char x/y word x/y) - all very
interesting information, particularly the word counter as an
'on-the-fly' routine, but (the word counter in particular),
time consuming on larger files.

In the end, just doing a TRichEdit.Lines.LoadFromFile on my
2mb test file takes about 10 seconds without doing any of
the information calculation - if I can cut that routine down
to a manageable size I can live with that - it's not like
most people go around opening 2mb text files very often
anyway, I just wanted to see how much time my program wasted
doing so.

In fact, it's not really that much slower than metapad at
the same task, and one of metapad's big things (from memory)
is how quickly it can open really big files...

I'm still looking at all the other things for my program.  
It's interesting how easy it is to create a basic text
editor (make a form, slap a TMemo or TRichText on it,
voila!) that's next to useless, and how more work is
involved in all the little things that mean so much in such
a program and really do make the difference between all the
ones available - stuff like clickable URL's and syntax
highlighting and all the little 'features' that your
favourite text editor has.  It's definately a very
interesting exercise.  (Not to mention one I have wanted to
do for awhile, given that of all the text editors out there,
i can't find a decent one which has a readable statusbar to
someone of my limited vision...)

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

Re:TMemo / TRichEdit Q's....


Quote
"OgO" <quent...@qjc.cjbGlasses.net> wrote in message

news:Xns92A3A0F0A5E80ogo1mynxwowaustcom@210.49.20.254...

Quote
> In comp.lang.pascal.delphi.misc, on 10 Oct 2002, Nicholas
> Sherlock announced:

> >> "Use MaxLength to limit the number of characters that can
> >> be entered into the edit control. A value of 0 indicates
> >> that there is no application-defined limit on the
> >> length."

> > The help is incomplete - setting MaxLength to 0 just makes
> > the maxlength default to the default length of that OS,
> > either 64k or 32k.

> Oh ok, but when I had MaxLength set to 0, the program did
> still try to load my 2MB file, and I don't know, if I'd left
> it however long, 5 mins, an hour, 2.... it might have loaded
> it, but thanks, I'll try changing it just to make sure.

strange, when testing I get about 5 seconds for a 1.4 meg (text) file

of which accorting to wndproc logs for the richedit
the logging doesn't slow it down much

1 second is actual EM_Streamin file loading called by richedit
   including erase of richedit contents
4 seconds is richedit doing something internally
  _then_  making the display

for url selection look at rxrichedit in the rx library
it has some extra functions
..unfortunately it seems to take about 2x longer to load a file

if you want really large files with quick response you will probably need to
develop your own display<-window onto file
or find a component to do it
it is unlikely a user will actually want to read a 30Mb file

some pointless numbers for an arbitrary file
(had this around from a while ago, I forget what some of the numbers meant
;-)
maybe
call depth,  seconds, clocktick  message/event

 1   2:40:59 PM 140247114 start loadrich
  1 2:40:59 PM 140247564 EM_Streamin >>>1 9106144 0
  1 2:40:59 PM 140247570  to oldproc EM_Streamin
  1   2:40:59 PM 140247576 47182 48206 BC4E UNKNOWN  >>>3052 9104608 0
  1   2:40:59 PM 140247589  to oldproc UNKNOWN
  1   2:40:59 PM 140247595  from oldproc UNKNOWN
  1   2:40:59 PM 140247599 WM_PAINT >>>0 0 0
  1   2:40:59 PM 140247599  to oldproc WM_PAINT
  2     2:40:59 PM 140247606 wm_erasebkgnd >>>4782 0 0
  2     2:40:59 PM 140247609  to oldproc wm_erasebkgnd
  2     2:40:59 PM 140247615  from oldproc wm_erasebkgnd
  1   2:40:59 PM 140247619  from oldproc WM_PAINT
  2     2:40:59 PM 140247619  streamload
     a heap of 4k loads issued by RE
  2     2:41:00 PM 140248674  streamload
     last stream block  .. now back in richedit to actually display it
  1   2:41:04 PM 140252485 47182 48206 BC4E UNKNOWN  >>>3052 9104696 0
  1   2:41:04 PM 140252489  to oldproc UNKNOWN
  1   2:41:04 PM 140252489  from oldproc UNKNOWN
  1   2:41:04 PM 140252498 WM_PAINT >>>0 0 0
  1   2:41:04 PM 140252499  to oldproc WM_PAINT
  2     2:41:04 PM 140252504 wm_erasebkgnd >>>9578 0 0
     etc
  0 2:41:05 PM 140252796  from oldproc EM_Streamin
  1   2:41:05 PM 140252799 end loadrich

Other Threads