Just as an aside, could u tell me why u are all
using pred(itemcount) instead of (itemcount - 1)????
----- Original Message -----
From: Stephen
Bertram
Sent: Friday, November 01, 2002 9:38 AM
Subject: RE: [DUG]: Friday Challange I've
done this in 5 different ways. One of the more flexible
is
function statement(Sep, Quote: String): string;
var
I: integer;
begin
Result := Sep;
for I := 0 to pred(ItemCount)
do
Result
:= format('%s%s%s%s%s',[Result,Sep,Quote,Item[I],Quote])
Delete(Result, 1, Length(Sep);
end;
The
main advantage of this is speed where the list is large - the conditional is
removed from the iteration.
(Note
that many variants of SQL limit the number of parameters in a list to 255 and
the length of the list to 2000 or 4000.)
One of
our standard method for comma separated lists is to use a stringlist (not
efficient but simple and avoids empty lists):
function statement(FieldName, EmptyCondition: String; Quote:
Boolean): string;
var
i integer;
ResList : TStringList;
begin
ResList := TStringList.Create;
for I := 0 to pred(ItemCount)
do
if Quote
ResList.Add(Format('''%s''',[Item[i]]))
else
ResList.Add(Item[i]);
if ResList.Count > 0 then
Result := Format('%s in (%s)',[FieldName,
ResList.CommaText]
else
Result :=
EmptyCondition;
ResList.Free;
end; Result := $0.02; Stephen
|
- RE: [DUG]: Quicky - the registry Andreas Toth
- Re[2]: [DUG]: Quicky - the registr... Alistair George
- RE: Re[2]: [DUG]: Quicky - the... Andreas Toth
- [DUG]: Quicky - the registry Alistair George
- [DUG]: Debugging DLL Phil Middlemiss
- RE: [DUG]: Debugging DLL Allan Vergara
- Re[2]: [DUG]: Quicky - the registr... Alistair George
- RE: [DUG]: Friday Challenge Leigh Wanstead
- RE: [DUG]: Friday Challange Myles Penlington
- RE: [DUG]: Friday Challange Stephen Bertram
- Re: [DUG]: Friday Challange Tracey Maule
- Re: [DUG]: Friday Challange Neven MacEwan
- Re: [DUG]: Friday Challange James Sugrue
- Re: [DUG]: Friday Challange Kurt at iadvance
- Re: [DUG]: Friday Challange James Sugrue
- Re: [DUG]: Friday Challange Tracey Maule
- Re: [DUG]: Friday Challange James Sugrue
- RE: [DUG]: Friday Challange Conor Boyd