BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Friday, July 28, 2006
TypInfo is cool!

uses
TypInfo;

type
TColorState = (CS_Red, CS_Blue, CS_Green);

procedure TForm1.Button1Click(Sender: TObject);
var
colorstate: TColorState;
begin
ColorState:= TColorState(GetEnumValue(TypeInfo(TColorState),'CS_Red'));
Edit1.Text:= GetEnumName(TypeInfo(TColorState), Ord(ColorState));
end;

Labels: , ,

posted by Brad Prendergast at 8:18:00 AM
Comments:
Yes they are... and if you design your enums to use a Delphi standard, you can write some simple helper functions to return text that is more human.

e.i.
In Classes.pas

TStringsDefined = set of (sdDelimiter, sdQuoteChar, sdNameValueSeparator,
sdLineBreak, sdStrictDelimiter);

write a function like:

GetHumanEnumName(TypeInfo(TStringsDefined), Ord(sdNameValueSeparator));

that results in text: "Name Value Seperator"
posted by Blogger John E Friday, July 28, 2006 12:00:00 PM  
Links to this post:

Create a Link

Recent Posts
 A bit, byte and word
 Having a little fun and getting a Callback
 Too much?
 Virtual PC Is Now Free!
 Who does not like cookies?
 DayLightTime
 A tale of ASP, Excel and a RecordSet
 Conversion Utility
 Custom Word Fields
 Adapter Information Round 2

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger