I think you can safely assume that an SQL query will have less than 100 or so joins, so no need for string buffers. Perhaps the *REAL* Friday challenge is to come with an SQL statement with > 100 joins!
Dennis. ----- Original Message ----- From: "Neven MacEwan" <[EMAIL PROTECTED]> To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> Sent: Friday, November 01, 2002 10:03 AM Subject: Re: [DUG]: Friday Challange > Dennis > > Therein lies the challange, to come up with an efficient 'Join' procedure > that > require no preknowlege of iteration count or item length > > would the format be sominthing like > > TJoinItemFunction = function(Index: integer): string; > TJoinOption = (joRemoveBlanks, joUnique, joCaseSensitive); > TJoinOptions = set of TJoinOption; > > function Join(GetItem: TJoinItemFunction ; count: integer; const Sep: > string, Options TJoinOptions): string; > > N > > > ----- Original Message ----- > From: "Dennis Chuah" <[EMAIL PROTECTED]> > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > Sent: Friday, November 01, 2002 9:36 AM > Subject: Re: [DUG]: Friday Challange > > > > > > 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/ > > > > -------------------------------------------------------------------------- - > 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/ > --------------------------------------------------------------------------- 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/