Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Component Question...

Posted on 1999-10-25
Medium Priority
Last Modified: 2010-04-04
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....

Question by:rjagan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 15

Accepted Solution

simonet earned 80 total points
ID: 2155434
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.



Author Comment

ID: 2157848
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...

LVL 15

Expert Comment

ID: 2158221
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 (



Author Comment

ID: 2158433
Hi alex,
     Much thanks for your help...


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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