Enumerations as class properties

Hello,
I am trying to define a enumeration list as a class property. The definition itself isn't a problem, but how can I get the enumerated items listed in the code completion? And does anybody know if I can select an enumerated item by providing his "index"? I looked for information about this topic in quite a few books and in the Delphi docs, but couldn't find anything about this special issue.
Thanks for any help!

Comments

  • [green]
    I dont know how and why, as yet. But I can say, CB's code completion is pathetically slow. Pathetic

    For your question, if you could provide a sample of what you're doing, I'd be most happy to help you! (Well, I will learn in the process myself, but thats another story!)[/green]
    [hr][red]~Bikram[/red]

  • : [green]
    : I dont know how and why, as yet. But I can say, CB's code completion is pathetically slow. Pathetic
    :
    : For your question, if you could provide a sample of what you're doing, I'd be most happy to help you! (Well, I will learn in the process myself, but thats another story!)[/green]
    : [hr][red]~Bikram[/red]
    :
    :

    Thank you for your help. Here is an example of what I am trying to do.
    I have a class definition like this:

    //======================================================================
    // Class declaration.
    //======================================================================
    type
    TDeviceAction = (devactOpen, devactClose);
    TDeviceStatus = (devstatOpened, devstatClosed, devstatUnavailable);
    TEpicDevice = class(TEpicIO)
    private
    { Private declarations }
    //----------------------------------------------------------------------
    // Class variables
    //----------------------------------------------------------------------
    fintDeviceNo : Integer;
    fintUserHandle : Integer;
    fDeviceStatus : TDeviceStatus;

    I have defined the enummerated types TDeviceAction and TDeviceStatus, which holds the possible values.
    Now I wand to make this enummerations accessible for other modules, defining this enummerations as properties. But I cannot find a way to do this. I don't know if this is possible in Delphi, but the ideal way would be to show this values in the Delphi code completion when calling a method of this class which uses on of this enummerated types as a parameter (like in VB, where the possible values are listed when writing the code for methods which expect some kind enumerated values).

    Regards,
    Peter
  • You can either put the declarations of your enumerated types into class' "public" section just same way like you added class variables into private, so they will be available from other units which use TEpicDevice and be shown in code completion too. If you want to be able to process event when value to these variables are written or read, you can write a property with read and write procedures which handle the variable writing and reading and can perform other tasks same time when value changes.

    example:
    [code]
    TDeviceAction = (devactOpen, devactClose);
    TDeviceStatus = (devstatOpened, devstatClosed, devstatUnavailable);
    TEpicDevice = class(TEpicIO)
    private
    fintDeviceNo : Integer;
    fintUserHandle : Integer;
    fDeviceStatus : TDeviceStatus;//holds actual value
    procedure SetDevStatus(Value: TDeviceStatus);
    function GetDevStatus: TDeviceStatus;
    public
    property DeviceStatus: TDeviceStatus read GetDevStatus write SetDevStatus;
    end;

    //...

    procedure TEpicDevice.SetDevStatus(Value: TDeviceStatus);
    begin
    //you can add other code here to do something when status chnages
    fDeviceStatus := Value;
    end;

    function TEpicDevice.GetDevStatus: TDeviceStatus;
    begin
    Result := fDeviceStatus;
    end;
    [/code]

    I hope I understood correctly what you wanted to do.
  • [b][red]This message was edited by zibadian at 2003-7-13 14:11:34[/red][/b][hr]
    : : [green]
    : : I dont know how and why, as yet. But I can say, CB's code completion is pathetically slow. Pathetic
    : :
    : : For your question, if you could provide a sample of what you're doing, I'd be most happy to help you! (Well, I will learn in the process myself, but thats another story!)[/green]
    : : [hr][red]~Bikram[/red]
    : :
    : :
    :
    : Thank you for your help. Here is an example of what I am trying to do.
    : I have a class definition like this:
    :
    : //======================================================================
    : // Class declaration.
    : //======================================================================
    : type
    : TDeviceAction = (devactOpen, devactClose);
    : TDeviceStatus = (devstatOpened, devstatClosed, devstatUnavailable);
    : TEpicDevice = class(TEpicIO)
    : private
    : { Private declarations }
    : //----------------------------------------------------------------------
    : // Class variables
    : //----------------------------------------------------------------------
    : fintDeviceNo : Integer;
    : fintUserHandle : Integer;
    : fDeviceStatus : TDeviceStatus;
    :
    : I have defined the enummerated types TDeviceAction and TDeviceStatus, which holds the possible values.
    : Now I wand to make this enummerations accessible for other modules, defining this enummerations as properties. But I cannot find a way to do this. I don't know if this is possible in Delphi, but the ideal way would be to show this values in the Delphi code completion when calling a method of this class which uses on of this enummerated types as a parameter (like in VB, where the possible values are listed when writing the code for methods which expect some kind enumerated values).
    :
    : Regards,
    : Peter
    :
    You can also define the properties like this:
    [code]
    TEpicDevice = class(TEpicIO)
    private
    { Private declarations }
    //--------------------------------------------------------------------
    // Class variables
    //----------------------------------------------------------------------
    fintDeviceNo : Integer;
    fintUserHandle : Integer;
    fDeviceStatus : TDeviceStatus;
    public
    property DeviceStatus: TDeviceStatus read fDeviceStatus write fDeviceStatus;
    end;
    [/code]
    This doesn't use any access methods.

  • : [b][red]This message was edited by zibadian at 2003-7-13 14:11:34[/red][/b][hr]
    : : : [green]
    : : : I dont know how and why, as yet. But I can say, CB's code completion is pathetically slow. Pathetic
    : : :
    : : : For your question, if you could provide a sample of what you're doing, I'd be most happy to help you! (Well, I will learn in the process myself, but thats another story!)[/green]
    : : : [hr][red]~Bikram[/red]
    : : :
    : : :
    : :
    : : Thank you for your help. Here is an example of what I am trying to do.
    : : I have a class definition like this:
    : :
    : : //======================================================================
    : : // Class declaration.
    : : //======================================================================
    : : type
    : : TDeviceAction = (devactOpen, devactClose);
    : : TDeviceStatus = (devstatOpened, devstatClosed, devstatUnavailable);
    : : TEpicDevice = class(TEpicIO)
    : : private
    : : { Private declarations }
    : : //----------------------------------------------------------------------
    : : // Class variables
    : : //----------------------------------------------------------------------
    : : fintDeviceNo : Integer;
    : : fintUserHandle : Integer;
    : : fDeviceStatus : TDeviceStatus;
    : :
    : : I have defined the enummerated types TDeviceAction and TDeviceStatus, which holds the possible values.
    : : Now I wand to make this enummerations accessible for other modules, defining this enummerations as properties. But I cannot find a way to do this. I don't know if this is possible in Delphi, but the ideal way would be to show this values in the Delphi code completion when calling a method of this class which uses on of this enummerated types as a parameter (like in VB, where the possible values are listed when writing the code for methods which expect some kind enumerated values).
    : :
    : : Regards,
    : : Peter
    : :
    : You can also define the properties like this:
    : [code]
    : TEpicDevice = class(TEpicIO)
    : private
    : { Private declarations }
    : //--------------------------------------------------------------------
    : // Class variables
    : //----------------------------------------------------------------------
    : fintDeviceNo : Integer;
    : fintUserHandle : Integer;
    : fDeviceStatus : TDeviceStatus;
    : public
    : property DeviceStatus: TDeviceStatus read fDeviceStatus write fDeviceStatus;
    : end;
    : [/code]
    : This doesn't use any access methods.
    :
    :
    Thank you all very much for your help, much appreciated! I will try this out today.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories