declare types in classes!

Posted on 2005-04-05
Medium Priority
Last Modified: 2010-04-05
I have two enumerations that hold identifiers with same name but with different order.
It seems that they cannot be used in the same unit as delphi will say"identifier redeclared".


It will work if they are in different units and I am doing it this way at the moment.
But just wanted to know if we can also declare such types inside classes to put under private or public directives?

Question by:xo310
  • 3
LVL 15

Assisted Solution

mikelittlewood earned 800 total points
ID: 13710096
As long as you declare the units declaring the types, you can reference them inside another class

type TMyOtherType = (B,D,A,C);

  TForm1 = class(TForm)
    Type1: TMyOtherType;
    Type2: TMyType;
    { Public declarations }

type TMyType = (A,B,C,D);

Just make sure Unit1 delcares Unit2 in its USES clause of the interface
LVL 12

Expert Comment

ID: 13710311
The classes are types, so it is impossible to be declared another types into the classes
LVL 12

Accepted Solution

esoftbg earned 200 total points
ID: 13710370
It is possible to be declared variables, properties into the classes, but not types. New types could be declared into the clause
but not into classes
LVL 12

Expert Comment

ID: 13710431
To avoid problems you could make declaration of the types this way:

     TMyType1 = (mt1A, mt1B, mt1C, mt1D);
     TMYType2 = (mt2B, mt2D, mt2A, mt2C);

Author Comment

ID: 13710877
Ahh just to clarify:)
I wanted to give 150p to mikelittlewood  and 100p to esoftbg but clicked wrongly in the split points page.
thanks a lot guys

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

750 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