Tracey Stylistic really I also finding typing pred(Count) is less error prone the - 1 sometimes gets lost
N ----- Original Message ----- From: "Tracey Maule" <[EMAIL PROTECTED]> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> Sent: Friday, November 01, 2002 10:48 AM Subject: Re: [DUG]: Friday Challange Just as an aside, could u tell me why u are all using pred(itemcount) instead of (itemcount - 1)???? ----- Original Message ----- From: Stephen Bertram To: Multiple recipients of list delphi 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 -----Original Message----- From: Neven MacEwan [mailto:neven@;mwk.co.nz] Sent: Friday, 1 November 2002 12:28 a.m. To: Multiple recipients of list delphi 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/