Solved

TMemo - How to add lines of text without scrolling

Posted on 2004-09-06
3
1,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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