> Thanks Aaron
> But why isn't TEnumType = (VB,Delphi,C++,C,Java) valid?
> and would it be so hard?
> also I found that  TEnumType =  (Left,Right,Up,Down) was valid but
> case TEnumType(OrdVal)
>   Left: ....; // error here as Left is property in scope of form

There's your reason why it's not practical... Namespaces overlap would
reduce the practicality of this practice terribly...

> This seems to be a scoping problem
> I'm not suggesting a total relax of rules (ie spaces in names ala SQL7)
> but it is frustrating that this is almost there but not really usable

I don't think that the scoping problem is resolvable in a practical fashion
unless the compiler was designed to disallow name overloading of previously
declared enumeration values to assist the programmer from tripping over his
own feet...

My personal belief is this form of Case Statement should almost never
be needed... Or can be converted to an EnumEntry easily enough as to
not be an issue... String comparison is expensive and definition of string
constants that are processed as strings in code are serious limitations to
future change or localisation...

My Enum definitions do something like this... This is our styleguide example
which provides TStrings management of enumeration and an encapsulated
naming source for each enum entry (in this case a constant array)...

interface
uses SysUtils, Classes;

type
    TProgress = (prNOTSTARTED,prINPROGRESS,prCOMPLETED);
    TProgresses = set of TProgress;

    function GetProgressString(Progress :TProgress):String;
    procedure GetProgressStrings(SL :TStrings);
    procedure GetMaskedProgressStrings(const Mask :TProgresses; SL :TStrings);
    function GetProgressFromList(SL :TStrings; Index :Integer):TProgress;

implementation
const
   ProgressNames :array[TProgress] of String =
     ('Not Started','In Progress','Completed');

function GetProgressString(Progress :TProgress):String;
begin
    result := ProgressNames[Progress];
end;

procedure GetProgressStrings(SL :TStrings);
var
    progress :TProgress;
begin
    SL.BeginUpdate;
    SL.Clear;
    for Progress := Low(Progress) to High(Progress) do
        SL.AddObject(GetProgressString(Progress),TObject(Progress));
    SL.EndUpdate;
end;

procedure GetMaskedProgressStrings(const Mask :TProgresses; SL :TStrings);
var
    progress :TProgress;
begin
    SL.BeginUpdate;
    SL.Clear;
    for Progress := Low(Progress) to High(Progress) do if Progress in Mask then
        SL.AddObject(GetProgressString(Progress),TObject(Progress));
    SL.EndUpdate;
end;

function GetProgressFromList(SL :TStrings; Index :Integer):TProgress;
begin
    result := TProgress(SL.Objects[Index]);
end;
  
--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to