Solved

Recognising diferent components...

Posted on 2000-02-24
12
150 Views
Last Modified: 2010-04-04
Suppose that I create next components:
TMyDBEdit (from TDBEdit), TMyDBText (from TDBText), etc.
So, what is the best way to ask is some object is one of my
components (not particulaly one but one of all)? But, without casting, becouse some time I can add some new component and don't want to change casting again and again!
Thanks!
0
Comment
Question by:grebov
[X]
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
12 Comments
 
LVL 2

Expert Comment

by:florisb
ID: 2553681
F.e. if you gives both components the same onClickevent:

if Sender is TMyDBEdit then
  TMyDBEdit(Sender).something := somethingelse
else if Sender is TMyDBText then
  TMyDBText(Sender).something := somethingelse

If use use propery's that are in both components (f.e. tag), you can use it without casting.

Floris.



0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2553683
hi grebov,

what about

if (Control is TMyDBEdit) then
or
if (Component is TMyDBEdit) then
or
if (Object is TMyDBEdit) then

>is there a way to use there DB properties whithout casting
i guess no

meikl
0
 
LVL 15

Expert Comment

by:simonet
ID: 2554314
<<<<<

if Sender is TMyDBEdit then
  TMyDBEdit(Sender).something := somethingelse
else if Sender is TMyDBText then
  TMyDBText(Sender).something := somethingelse

>>>>

This won't work quite as desired, since TMyDBText is inherited from TMyDBEdit. It will pass both tests.

A fix up would be to invert the tests, starting from the outmost class (TMyDBEdit) and then to the parent classes (TDBEdit, TCustomEdit, etc).

Yours,

Alex
0
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!

 

Author Comment

by:grebov
ID: 2557510
Edited text of question.
0
 

Author Comment

by:grebov
ID: 2557513
Adjusted points to 200
0
 

Author Comment

by:grebov
ID: 2561526
Adjusted points to 300
0
 

Author Comment

by:grebov
ID: 2561572
None of the comments satisfied me,
so I decided to delete my question
and to ask a new one that is similar.
0
 

Author Comment

by:grebov
ID: 2561573
This question has a deletion request Pending
0
 

Author Comment

by:grebov
ID: 2568412
I found the answer by myself!
Here it is:
All components must implement the
same interface, for ex: IMyI
and, then, just ask:

for i:=0 to ComponentCount-1 do
if Components[i].GetInterface(IMyI,Temp)
then showmessage(Components[i].Name);

And none of your "experts" didn't
know the answer, so PLEASE
give mi my points BACK!!!
0
 
LVL 2

Expert Comment

by:florisb
ID: 2568472
This question no longer is pending deletion
0
 
LVL 2

Expert Comment

by:florisb
ID: 2568473
I object, Simonet and I gave you the anser. Do check what you asked here.

errr, none of the experts didn't know = all experts knew. Do check your logic greboy.

Floris.

0
 

Accepted Solution

by:
vanja1 earned 300 total points
ID: 2573602
You can try to use Interfaces as a way
of multiple inheritance. All of your
components should have the same ancestor.

Bye,
vanja1
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

636 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