Link to home
Start Free TrialLog in
Avatar of coppola
coppola

asked on

Integers and Enumerated Types


Does anyone know how to accomplish this?

type
  TMonths = (January, February, March, etc.);

var
  WhichMonth : TMonths;

...

  Form1.Tag := ord(WhichMonth);
 
  {More Code}

  WhichMonth := TMonth(Form1.Tag)  <<== This is the problem

...

How do you get from an integer type to an enumerated type?

ASKER CERTIFIED SOLUTION
Avatar of alona041797
alona041797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mheacock
mheacock

Ah, reject it...just out of principle...she/he used CAPS, which is akin to her/he shouting at you!!  Heh heh.

But I might want to answer this..... *sigh*
Avatar of coppola

ASKER

My problem was not a typo. I'm using TMonths as an example. My code is more involved and I thought that this would be easier to follow using months.

The problem persists. The error I get is at compile time:
Incompatible Types integer and TModules

The actual code generating the error is:

  previousModule := currentModule;
  currentModule := constructModuleFromID(TModules(TMenuItem(Sender).Tag));
  if currentModule <> nil then begin
    currentModule.Start;
    previousModule.Free;
    end;

A little more research has led me to believe that this is an order of evaluation problem. If I declare a TModules variable and perform the type conversion before the function call, it works.