🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by na Wed, 28 May 2008 18:36
Delphi threading by example article in C++ Builder 2007 format
#285
Author: na
Date: Wed, 28 May 2008 18:36
9 lines
1213 bytes
In the Delphi threading by example article presented here:
http://dn.codegear.com/article/22411

I would like to implement a portion of this using C++ Builder. What is the correct syntax
for this funtion?

procedure HandleMessage(var Message: TMessage); message TH_MESSAGE;

I take it I need to use BEGIN_MESSAGE_MAP macros? 
Re: Delphi threading by example article in C++ Builder 2007 format
#287
Author: Remy Lebeau (TeamB)
Date: Wed, 28 May 2008 20:11
30 lines
1789 bytes
"na" <na@na.com> wrote in message news:483da620$1@newsgroups.borland.com...

> In the Delphi threading by example article presented here:
> http://dn.codegear.com/article/22411
>
> I would like to implement a portion of this using C++ Builder.
> What is the correct syntax for this funtion?

Use a MESSAGE_MAP for that, ie:

    private:
        MESSAGE void __fastcall HandleMessage(TMessage &Message);

    public:
        BEGIN_MESSAGE_MAP
            VCL_MESSAGE_HANDLER(TH_MESSAGE, TMessage, HandleMessage)
        END_MESSAGE_MAP(TForm)


    void __fastcall TForm1::HandleMessage(TMessage &Message)
    {
        //....

        // this is not required for user-defined messages
        TForm::Dispatch(&Message);
    }


Gambit 
Re: Delphi threading by example article in C++ Builder 2007 format
#286
Author: na
Date: Wed, 28 May 2008 20:35
28 lines
1742 bytes
Thank you Remy. Would you mind inspecting the following to see if it looks ok? It is very
brief to keep it simple. It works on my Quad core...

//File.h
class MSGObject
{
 private:
 public:
 std::string sLogMessage;
 std::string sWrkStation;
};

//File.cpp
void TForm1::OnMessage(TMessage & Message)
{
 if (Message.WParam == TH_COMPUTER)
  {
    MSGObject* pMSGObj = (MSGObject*)Message.LParam;
    lb_Computer->Caption = pMSGObj->sWrkStation.c_str();
    delete pMSGObj;
    pMSGObj = 0;
  }
}

//From a Thread
MSGObject * MSGObj = new MSGObject;
MSGObj->sWrkStation = "Some Value";
PostMessage(Form1->Handle, TH_MESSAGE, TH_COMPUTER, (long)MSGObj);
Re: Delphi threading by example article in C++ Builder 2007 format
#288
Author: Remy Lebeau (TeamB)
Date: Wed, 28 May 2008 23:04
27 lines
1901 bytes
"na" <na@na.com> wrote in message news:483dc218$1@newsgroups.borland.com...

> Would you mind inspecting the following to see if it looks ok?

You can do away with the wrapper class altogether, it is not needed:

    void TForm1::OnMessage(TMessage &Message)
    {
        if( Message.WParam == TH_COMPUTER )
        {
            AnsiString *pWrkStation = (AnsiString*) Message.LParam;
            lb_Computer->Caption = *pWrkStation;
            delete pWrkStation;
        }
    }

    AnsiString *pWrkStation = new AnsiString("Some Value");
    if( !PostMessage(Form1->Handle, TH_MESSAGE, TH_COMPUTER, (LPARAM) 
pWrkStation) )
        delete pWrkStation;

Either way, though, just make sure your TForm is actually processing all 
TH_MESSAGE messages, or you will leak your allocated objects/strings.


Gambit 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads