grebov
asked on
Recognising diferent components...
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!
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!
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
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
<<<<<
if Sender is TMyDBEdit then
TMyDBEdit(Sender).somethin g := somethingelse
else if Sender is TMyDBText then
TMyDBText(Sender).somethin g := 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
if Sender is TMyDBEdit then
TMyDBEdit(Sender).somethin
else if Sender is TMyDBText then
TMyDBText(Sender).somethin
>>>>
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
ASKER
Edited text of question.
ASKER
Adjusted points to 200
ASKER
Adjusted points to 300
ASKER
None of the comments satisfied me,
so I decided to delete my question
and to ask a new one that is similar.
so I decided to delete my question
and to ask a new one that is similar.
ASKER
This question has a deletion request Pending
ASKER
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!!!
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
then showmessage(Components[i].
And none of your "experts" didn't
know the answer, so PLEASE
give mi my points BACK!!!
This question no longer is pending deletion
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.
errr, none of the experts didn't know = all experts knew. Do check your logic greboy.
Floris.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if Sender is TMyDBEdit then
TMyDBEdit(Sender).somethin
else if Sender is TMyDBText then
TMyDBText(Sender).somethin
If use use propery's that are in both components (f.e. tag), you can use it without casting.
Floris.