🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9473

Re: Callback function as method class

#9473
From: Remy Lebeau (TeamB)
Date: Fri, 09 Jul 2004 09:27
43 lines
1943 bytes
"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: <40ee651d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40ee3b69@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,68c63a4b5ad1dd83
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40ee3b69@newsgroups.borland.com>
Subject: Re: Callback function as method class
Date: Fri, 9 Jul 2004 02:27:48 -0700
Lines: 46
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: 68.69.17.10
Message-ID: <40ee651d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1089365277 68.69.17.10 (9 Jul 2004 02:27:57 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail