Article View: borland.public.cppbuilder.nativeapi
Article #7153Re: Create event at runtime
From: Andrue Cope [TeamB]
Date: Tue, 08 Mar 2005 10:37
Date: Tue, 08 Mar 2005 10:37
40 lines
2176 bytes
2176 bytes
Christophe MINETTI wrote:
> I would like to know how to create an event at runtime;
Well you can't create the event at runtime since that would mean
generate executable code but you can attach an existing event or event
like method to a different object at runtime.
The easy way is to create the event is using the Object Inspector and a
dummy object. You then assign the event where it's needed at runtime.
So for your example at design time you could create a dummy TImage
called Image1 and give it an OnMouseMove event. Then at runtime you do:
TImage * myImage=new TImage( this );
myImage->OnMouseMove=Image1->OnMouseMove;
But alternatively you can create your own event handler by making it a
method of your form. For this I find it easiest to again first create
an event using the Object Inspector and then just copy the function
declaration with my own name:
void __fastcall wibble(TObject *Sender, TShiftState Shift,
int X, int Y);
..and of course write my own body for it.
Then you'd have:
TImage * myImage=new TImage( this );
myImage->OnMouseMove=wibble;
Events are really just slightly complicated function pointers and if
you use the above techniques you can ignore the complexity for the most
part.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<422d80ac@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<422D782E.3B97CE03@ulb.ac.be>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,157c035af5a44151 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Re: Create event at runtime Newsgroups: borland.public.cppbuilder.nativeapi References: <422D782E.3B97CE03@ulb.ac.be> Date: Tue, 8 Mar 2005 10:37:14 +0000 User-Agent: XanaNews/1.17.2.7 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <422d80ac@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1110278316 217.207.223.34 (8 Mar 2005 02:38:36 -0800) Lines: 40 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail