Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing faster to a memo box 2

Status
Not open for further replies.

jos100

Programmer
Nov 21, 2006
2
0
0
NO
Hi !

Any method to load charachters faster in to
a memo box ?

for i:= 1 to 10000 do

memo1.text := memo1.text + x; // x is an array of char.

is slow at the end.

memo1.text := x // not legal.
 
Make up a real string first:

var
S: String; { huge string I hope }

begin
S := '';
for i := 1 to LengthOfArrayX do
S := S + X;

Form1.memo.Text := S; // fast !

 
Adding characters to the end of a string can be slow for long strings. This time penalty be avoided by using SetLength to set the maximum length of the string before the for loop. So grg999's code can be improved as follows:
Code:
var
  s: string;
  ...
begin
  s := '';
  SetLength( s, LengthOfArrayX );
  for i := 1 to LengthOfArrayX do
    s := s + X[i];
end;

Andrew
Hampshire, UK
 
If you're not using Delphi 2006, then I would suggest using the FastMM4 memory manager for applications like this


Unzip to ..\Delphi\Lib\FastMM4 preserving the folder structure, add that folder to Delphi's search path, and then modify the .DPR project file of any project you want to use it in and add [tt]FastMM4[/tt] as the first unit in the uses clause. ie.

Code:
[b]program[/b] ImportantProg;

[b]uses[/b]
  FastMM4, Forms;
  [navy]// snip[/navy]

This memory manager is much quicker than the Borland's built in one, so much so that Borland included it in Delphi 2006 as the memory manager.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top