Article View: borland.public.cppbuilder.nativeapi
Article #9474Re: Callback function as method class
From: Sam
Date: Fri, 09 Jul 2004 09:38
Date: Fri, 09 Jul 2004 09:38
54 lines
2426 bytes
2426 bytes
Remy, thank you for your sample, but I use BCB 5 and it seems that
MakeObjectInstance is for the version later, because in the help there is no
link.
Samir
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> a οΏ½crit dans le
message de news:40ee651d$1@newsgroups.borland.com...
>
> "Sam" <skneife3@wanadoo.fr> wrote in message
> news:40ee3b69@newsgroups.borland.com...
>
> > The compiler refused. It seems that a class can't has
> > a callback as method, that is right ?
>
> Typically, to make a class method work as a callback, the method has to be
> declared as 'static'. However, in this particular case, you are using a
> window procedure. The VCL has a special function, MakeObjectInstance(),
> that can convert a non-static class method into a window procedure
callback.
> For example:
>
> class TMyClass
> {
> private:
> void* Ptr;
> public:
> TMyClass();
> ~TMyClass();
> };
>
> TMyClass::TMyClass()
> {
> Ptr = MakeObjectInstance(NewWindowProc);
> // you can use Ptr anywhere you need to assign a callback window
> procedure
> }
>
> TMyClass::~TMyClass()
> {
> FreeObjectInstance(Ptr);
> }
>
> void __fastcall TMyClass::NewWindowProc(TMessage &Message)
> {
> ...
> Message.Result = DefWindowProc(hSomeWnd, Message.Msg,
> Message.WParam, Message.LParam);
> }
>
>
> Gambit
>
>
>
Technical Details
Message-ID:
<40ee67a8@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40ee3b69@newsgroups.borland.com> <40ee651d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,68c63a4b5ad1dd83 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII Reply-To: "Sam" <skneife3@wanadoo.fr> From: "Sam" <skneife3@wanadoo.fr> Newsgroups: borland.public.cppbuilder.nativeapi References: <40ee3b69@newsgroups.borland.com> <40ee651d$1@newsgroups.borland.com> Subject: Re: Callback function as method class Date: Fri, 9 Jul 2004 11:38:57 +0200 Lines: 56 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 80.13.245.243 Message-ID: <40ee67a8@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089365928 80.13.245.243 (9 Jul 2004 02:38:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail