Solved

TMemo - How to add lines of text without scrolling

Posted on 2004-09-06
3
1,107 Views
Last Modified: 2008-03-17
Using a TMemo component, and the .Lines.Add method to add text to the component, how do I keep the TMemo from scrolling downward as I add new text to the component?  In other words, if I use .Lines.Add 1000 times, the top line of the TMemo will be out of sight, and the last line will be visible in the TMemo.  I would prefer if the TMemo would cease scrolling while new lines are added.  Yes, I know how to rescroll the viewport/scrollbar back to the top, but this causes a flicker, and I'd much prefer to keep the TMemo frozen until all the new text has been added to it.

How can I perform this?

Thanks.
0
Comment
Question by:Monroe406
  • 2
3 Comments
 
LVL 4

Expert Comment

by:Evarest
ID: 11991275
Maybe best to add these lines to a TStringList first and then copy its contents to your memo. This will be _a lot_ faster and you won't have any flickering to worry about...

procedure Add1000Lines;
var
 Q: integer;
 List: TStringList;
begin
 List :=TStringList.Create;
 for Q :=0 to 999 do
  begin
   List.Add(inttostr(Q));
  end;
 Memo1.Lines.AddStrings(List);
 List.Clear;
 List.Free;
end;

Of course, you'll need to alter this code to suite your needs...

Kind regards,
Evarest
0
 
LVL 4

Accepted Solution

by:
Evarest earned 50 total points
ID: 11991285
BTW, you can "freeze" the memo by calling BeginUpdate and EndUpdate:

procedure Add1000Lines;
var
 Q: integer;
begin
 Memo1.Lines.BeginUpdate;
 try
  for Q :=0 to 999 do
   begin
    Memo1.Lines.Add(inttostr(Q));
   end;
 finally
  Memo1.Lines.EndUpdate;
 end;
end;

Evarest

0
 

Author Comment

by:Monroe406
ID: 11991329
The BeginUpdate / EndUpdate methods are all I really need.  Adding these 2 lines before and after my .Lines.Add will meet my needs.  Thanks.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question