Solved

Integers and Enumerated Types

Posted on 1997-04-19
3
161 Views
Last Modified: 2010-05-18

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?

0
Comment
Question by:coppola
3 Comments
 
LVL 2

Accepted Solution

by:
alona041797 earned 50 total points
ID: 1335536
Your code is correct, except it is TMonths and not TMonth:

This:
  WhichMonth := TMonths(Form1.Tag);
should work.

If this is not the problem please type the error you get.
DO NOT REJECT THIS ANSWER!
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335537
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*
0
 

Author Comment

by:coppola
ID: 1335538
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.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
can't find the executable in Simulator 1 101
Adoquery sql  left join does not work 25 99
Dynamically Created Query 3 62
Firemonkey allowing RTL on android 6 47
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question