It depends on the size of your loop. If you are going to be appeding a
great number of strings, then I would suggest a string buffer approach -
where each iteration of the loop writes one string into the string buffer,
while an int variable is incremented with the length of the string. Then
create a string with the length of the int. In another loop, take the
strings from the buffer and write to the allocated string.
I have done tests with loops in sizes ranging from 10, 100, 1000, through to
1mil. The time savings for the 1mil loop is several oders of magnitude. I
won't bother for anything less than 100.
Dennis.
----- Original Message -----
From: Neven MacEwan
To: Multiple recipients of list delphi
Sent: Friday, November 01, 2002 12:27 AM
Subject: [DUG]: Friday Challange
Hi all,
Further to my enpty string question, I'm writing a lot of
functions that return a set of strings joined by a separator
ie 'col1, col2,...' or 'col1 = 'a' and colb = 'b'' (as you may guess
these are all parts of SQL Statements)
given a function 'Itemcount' that returns the number of items
and item(i) that returns the item string, and function sep what is the
best form of such a function
to seed the duscussion I'll give you one of my variants
function statement: string;
var
I: integer;
begin
Result := '';
for I := 0 to pred(ItemCount) do
if I = 0 then Result := Item(I)
else Result := format('%s%s%s',[Result,Sep,Item(I)])
end;
Variants and explainations pls
Neven
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/