Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get the Object name

3 views
Skip to first unread message

Danid

unread,
Feb 15, 2006, 5:27:17 AM2/15/06
to

Hello,
I place a TImage (I name it img1) on a form. How can i get the name of the image by clicking on it?

img1OnClick(TObject *Sender)
{
String imageName = ...;
ShowMessage (imageName );
}

Thanks,

Hans Galema

unread,
Feb 15, 2006, 6:49:15 AM2/15/06
to
Danid wrote:

> I place a TImage (I name it img1) on a form. How can i get the name of the image by clicking on it?

,

img1OnClick(TObject *Sender)
{
TImage *Image = dynamic_cast<TImage*>(Sender);

if ( Image )
ShowMessage ( Image->Name() );
}

Hans.

Unknown

unread,
Feb 15, 2006, 6:53:35 AM2/15/06
to
sorry,
i thought component name...


Unknown

unread,
Feb 15, 2006, 6:50:59 AM2/15/06
to
ShowMessage(img1->Name);

or generally

ShowMessage(dynamic_cast<TComponent*>(Sender)->Name);

Ο "Danid" <nos...@email.com> έγραψε στο μήνυμα
news:43f31015$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Feb 15, 2006, 1:43:40 PM2/15/06
to

"Hans Galema" <not...@notused.nl> wrote in message
news:43f3...@newsgroups.borland.com...

> TImage *Image = dynamic_cast<TImage*>(Sender);

If the OnClick handler is only assigned to TImage objects, and never caled
manually, then use static_cast instead:

TImage *Image = static_cast<TImage*>(Sender);

> ShowMessage ( Image->Name() );

'Name' is a property, not a fuction:

ShowMessage(Image->Name);


Gambit


Hans Galema

unread,
Feb 15, 2006, 2:09:45 PM2/15/06
to
Remy Lebeau (TeamB) wrote:

> 'Name' is a property, not a fuction:
>
> ShowMessage(Image->Name);

A property can be a function too. Look at all kinds of events.

typedef void __fastcall (__closure *OnClientConnectEvent)(TCustomWinSocket *Socket );

OnClientConnectEvent FOnClientConnect;

__property OnClientConnectEvent
OnClientConnect ={read=FOnClientConnect,write=FOnClientConnect};

Using OnClientConnect directly one would need a functioncall:

OnClientConnect(Socket);

But here it was Name yes. My mistake.

Hans.

0 new messages