Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-13 Thread Alister Christie
I believe the refactoring engine has problems with with statements. Which is probably in itself enough of a reason for me to stop using them. Alister Christie Computers for People Ph: 04 471 1849 Fax: 04 471 1266 http://www.salespartner.co.nz PO Box 13085 Johnsonville Wellington Ross

RE: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-11 Thread John Bird
I thought using with with a single argument, not nested, would be a clean and elegant practice, like: with stringgrid1 do begin cells[5,tcgmax]:=uline; cells[6,tcgmax]:=uline; nextstrgrdMaTC; cells[3,tcgmax]:='Totals'; cells[5,tcgmax]:=inttostr(trntotu);

RE: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-11 Thread Ross Levis
I tend to do this as well when it is obviously quite safe and saves a lot of typing. The problem is debugging. The debugger (in D7 anyway) will not resolve the variables unless they are fully qualified on the line. I have always found this very annoying. Code Insight resolves everything fine

RE: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Stephen Barker
Interesting stuff... Is it just me or is anyone else horrified by the with statement abuse in example function getStructures? Steve -Original Message- From: Sean Cross [mailto:[EMAIL PROTECTED] Sent: Thursday, 10 May 2007 1:49 p.m. To: NZ Borland Developers Group - Delphi List

Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Neven MacEwan
Steve Please explain? also why you are at it why is the diminutive of Stephen Steve? Neven Interesting stuff... Is it just me or is anyone else horrified by the with statement abuse in example function getStructures? Steve -Original Message- From: Sean Cross [mailto:[EMAIL

Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Jeremy North
Is it just me or is anyone else horrified by the with statement abuse in example function getStructures? I'm horrified by any use of the with statement. ___ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin:

Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Neven MacEwan
Jeremy I always though they should enhance the with statement with and as clause ie if ( Components[ siCom ] is TAdoDataSet ) then with ( Components[ siCom ] as tAdoDataSet ) as Dataset do begin Dataset.Open; ... otherwise I do var DataSet: tAdoDataSet; if (

RE: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Stephen Barker
Hi Neve :) I'm not one of the many who don't use the with statement at all, but I only use it sparingly and never nested 3 levels deep like the example. I usually end up removing it during debug sessions anyway and kick myself for using it in the first place. I think your mate Malcolm Groves

Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Neven MacEwan
Stephe (Nah doesn't work) I certainly agree as far as to say this part of the language construct is broken, but then I hate having to declare a temp var for no purpose at all but to remove ambiguity in references N Hi Neve :) I'm not one of the many who don't use the with statement at all,

Re: [DUG] Why use a set when a string will work OK (and less code )?

2007-05-10 Thread Jeremy North
I certainly agree as far as to say this part of the language construct is broken, but then I hate having to declare a temp var for no purpose at all but to remove ambiguity in references I tend to think of it as writing more readable/maintainable code.

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Sean Cross
Because then you are forever checking status with code like If Status = 'Active' then .. Else if Status = 'Pending'... So you end up using consts. And you still have the problem that your Status may end up as '' or 'Ative' or 'as323' And you can't use case statements. If status is purely

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Paul Heinz
Sean Cross wrote: TMyStatus = (Active, Pending, Ended, Paused, Deleted, Suspended); StatusMeanings = array[TMyStatus] of string = ('Active', 'Pending', 'Ended', 'Paused', 'Deleted', 'Suspended'); ... ShowMessage(StatusMeanings[Status]); Also, Delphi can do this for you using RTTI - this is

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Nick
Hi Sean, Thanks for the reply. Indeed I can see the benefit and use them in other parts of my program - but for something like status which does get acted on and displayed I was wondering what was best. You example code below would solve my initial query - thanks for that! :-) Sean Cross

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Leigh Wanstead
Take advantage compile time checking. Strong typecast check. Regards Leigh http://www.smootharm.com -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Nick Sent: Thursday, May 10, 2007 10:49 AM To: NZ Borland Developers Group - Delphi List Subject: [DUG] Why

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Nick
Nice thats even shorter :-) So following on from this, what happens when you want to do something like this TMyStatus = (Active, Pending, Ended, Paused, Deleted, Suspended); TLogLevel = (Normal,Error,Ended); This will cause an error as Ended appears twice. How you can you get around this?

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Conor Boyd
Yes, or if you want more control over your descriptive values, then you can do something like this: TGalleryStatus = (gsUnknown, gsSuccess, gsMajVerInvalid, gsMinorVerInvalid, gsVerFmtInvalid, gsVerMissing, gsPasswordWrong, gsLoginMissing, gsUnknownCommand,

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Myles Penlington
Nope - Look at the call - uses TypeInfo(TMyStatus), and for the other case should be TypeInfo(TLogLevel). M. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nick Sent: Thursday, 10 May 2007 11:29 To: NZ Borland Developers Group - Delphi List Subject:

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Nick
Indeed, but I mean just doing this type TMyStatus = (Active, Pending, Ended, Paused, Deleted, Suspended); TLogLevel = (Normal,Error,Ended); (as in, just writing that) wont compile as I get an error 'Identifier redeclared: Ended' Myles Penlington wrote: Nope - Look at the call - uses

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Neven MacEwan
Nick Thats why you use a lower case prefix ie tmsActive, tmsPending, ... verssu tllNormal, tllError, tllEnded... HTH Neven Nice thats even shorter :-) So following on from this, what happens when you want to do something like this TMyStatus = (Active, Pending, Ended, Paused, Deleted,

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Nick
aa ;-) Time for another coffee! Thanks heaps guys, I have learned a stack! Neven MacEwan wrote: Nick Thats why you use a lower case prefix ie tmsActive, tmsPending, ... verssu tllNormal, tllError, tllEnded... HTH Neven Nice thats even shorter :-) So following on from this, what

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Myles Penlington
Or you can put it into another unit, and then when you use it prefix it with the unit name, which in effect becomes a namespace. Myles. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Neven MacEwan Sent: Thursday, 10 May 2007 11:37 To: NZ Borland

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Tim Jarvis
Also, enumerated types are ordinal types, this means you can use them in case statements instead of having to use nested if's (which is what you would have to do with strings) Cheers Tim. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leigh Wanstead

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread John Bird
I like this a lot !!!: TGalleryStatusDescriptions: array [Low(TGalleryStatus)..High(TGalleryStatus)] of String = I have been trying to find out where I can use other variables in array declarations. I hoped I could use previously declared constants, I did not know I could use a function that

Re: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Jeremy North
I like this a lot !!!: TGalleryStatusDescriptions: array [Low(TGalleryStatus)..High(TGalleryStatus)] of String = You don't have to do that, you can just do this: TGalleryStatusDescriptions: array[TGalleryStatus] of String = Just like for booleans you can do: BoolStr: array[Boolean] of

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Conor Boyd
Yeah, I remembered that when I saw that Sean had posted almost the same type of example. ;-) Thanks, C. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jeremy North I like this a lot !!!: TGalleryStatusDescriptions: array

RE: [DUG] Why use a set when a string will work OK (and less code)?

2007-05-09 Thread Sean Cross
Q. What is the function to return the enum name? A. See http://www.techtricks.com/delphi/enumname.php Regards Sean Cross IT Systems Development Manager Catalyst Risk Management PO Box 230 50 Dalton St Napier 4140 DDI: 06-8340362 mobile: 021 270 3466 Visit us at http://www.catalystrisk.co.nz/