Solved

Integers and Enumerated Types

Posted on 1997-04-19
3
148 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now