Component Question...

Hi All,
   I'am basically trying to write a component
with the instance of another component in its
private access. Let me brief things...


  TState =(MA,LA,SF,MN)

   property State : TState read Mstate write Mstate

This is my first component..

In the second component I have the same
TState property to be used and in my second
component if i set the should
set the MyComponents state...This is my

So in the second component declared the
TState and also created the property enhanced
state(property). The problem i face is that
if i tried to set the property of MyComponent's
state from the second component it says

   Mycomponent.state and Secondcomponent.state
is incompatible? So cooly i created an unit
that contains all the type declarations and
used in both units...It worked cool? I know
this question is trivial... But please
explain me how to solve this problem without
using the unit stuff..

Also I'am looking for a cool component tutorial
or any book that deals with in and out of
delphi components?

Please help me out

Thanks in advance....

Who is Participating?
simonetConnect With a Mentor Commented:
Try this:

  TState =(MA,LA,SF,MN);

  TMyComponentA = class(TObject)
    FState : TState;

    State : TState read FState write FState ;

Note that TState's type definition must be declared outside the class definition for your component. Also note that there must be ONLY ONE definition for TState. If you need to use the type TState in another component that is in another class, then you mustn't redeclare TState, but add the unit where TState was first declared to the uses clause of the other component.

If there are multiple definitions of TState, then they will be different.

The best solution for this is to have another unit which only declares stuff that will be common to other units, such as the TState type declaration. Then just add "state.pas" (for example) to all units that use it.

You can add "state.pas" to the interface section uses clause.


rjaganAuthor Commented:
Hi alex,
    Thanks a lot for your help. so my type definition, that i've discussed in the question is the best way? Is that right.

I'am also looking for a site / book which talks about in and out of component building and inner workings...

Can you please suggest me one..

Thanks once more...

Your type definition is correct, Jagan. Just make sure you define it only once.

There is one great site for component writing:

About books, Ray Kanopka has written "Writing Delphi 3 Custom Components" (

Another graet book is "Hidden Paths of Delphi 3", which explores the ToolsAPI (experts, component and property editors) to depths never imagined before. "Hidden Paths..." is published by MCP (


rjaganAuthor Commented:
Hi alex,
     Much thanks for your help...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.