Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect an object's name

Status
Not open for further replies.

Han777

Programmer
Dec 12, 2007
19
I create two different instances of a class, objectA and objectB. in the procedure method of the class how do I ask
1) whether the currently processing object is objectA
2)what the name of the currently processing object is?

I don't want to test to see what the class "is" because both objects are of the same class.

Thank you for this excellent forum support.
 
add a 'Name' property to your class, or make a descendant from TComponent...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
use 'findcomponent' to get a "handle" on the ones you have named
This function works with graphical 'DIL' switchs, the switches are form objects here but they could be part of your own class.
Code:
function TMotorcontrol.EvalSwitch(Temp: integer; State: boolean; BitPos: integer; CompName: string): Boolean;
var switch: TComponent;
    index: integer;
begin
   result := State;
   switch := findcomponent(CompName);
   if Switch <> nil then
         if boolean(Temp and BitPos) <> State then   // state has changed
            begin
               State := boolean(Temp and BitPos);  // Get new state
               TImage(Switch).Picture.Assign(nil);
               if state then index := 1 else index := 0;
               DilSwitches.getbitmap(index, TImage(Switch).Picture.BitMap);
               result := state;  // return new state
            end;
end;

Steve: N.M.N.F.
Playing the blues isn't about feeling better. It's about making other people feel worse.
 
steve, findcomponent will only work if his object descends from TComponent, which is not sure since his object has no Name property (which is available in TComponent)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanks guys. declaring a name worked fine. Thanks for pointing out the findcomponent function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top