[DUG] Why use a set when a string will work OK (and less code)?
Nick
nick at salehoo.com
Thu May 10 11:37:19 NZST 2007
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 TypeInfo(TMyStatus), and for the other
> case should be TypeInfo(TLogLevel).
>
> M.
>
>
> -----Original Message-----
> From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
> 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)?
>
> 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?
>
>
>
>
> Paul Heinz wrote:
>
>> 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 how enum
>> properties work inside .dfms i.e. translating to/from string
>>
> constants.
>
>> Uses
>> TypInfo;
>>
>> ShowMessage(GetEnumName(TypeInfo(TMyStatus), Integer(Status));
>>
>> TTFN,
>> Paul.
>>
>> _______________________________________________
>> NZ Borland Developers Group - Delphi mailing list
>> Post: delphi at delphi.org.nz
>> Admin: http://delphi.org.nz/mailman/listinfo/delphi
>> Unsubscribe: send an email to delphi-request at delphi.org.nz with
>>
> Subject: unsubscribe
>
>>
>>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
>
> Attention:
> This communication is confidential and may be legally privileged. If you are not the intended recipient, please do not use, disclose, copy or distribute it, other than to return it to us with your confirmation that it has been deleted from your system.
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
>
>
More information about the Delphi
mailing list