🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Thread

#14091
From: Remy Lebeau (TeamB)
Date: Tue, 26 Aug 2003 19:02
58 lines
2647 bytes
"saravanan" <Saravanan@opussoft.com> wrote in message
news:3f4b8d2f$1@newsgroups.borland.com...
> My problem is how can i ensure that XControl has been created
> before executing the below mentioned line :
<snip>

The simpliest approach would be to pass the desired values as parameters to
the thread's constructor, store them into private variables, and then let
the Execute() assign the properties after it creates the object.  Then the
main thread doesn't have to worry about waiting at all.

For example:

    class TServiceThread : public TThread
    {
    private:
        TColor FBackground, FForeground;
        TXControl *XControl;
    protected:
        void __fastcall Execute();
    public:
        __fastcall TServiceThread(TColor Background, TColor Foreground);
    };

    __fastcall TServiceThread::TServiceThread(TColor Background, TColor
Foreground)
        : TThread(true)
    {
        FreeOnTerminate = true;
        FBackground = Background;
        FForeground = Foreground;
        Resume();
    }

    void __fastcall TServiceThread::Execute()
    {
        XControl = new TXControl(NULL) ;
        XControl->BackgroundColor = FBackground;
        XControl->ForegroundColor = FForeground;
        XControl->ProcessMessage() ;
        delete XControl;
    }

Then the main thread simply has to create the thread and let it do its thing
on its own:

    new TServiceThread(mBackground, mForeground);


Gambit



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
Technical Details
Message-ID: <3f4baea7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f4b8d2f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,d3c99904b7c174bd
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-26 12:13:05 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f4b8d2f$1@newsgroups.borland.com>
Subject: Re: Thread
Date: Tue, 26 Aug 2003 12:02:00 -0700
Lines: 60
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3f4baea7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061924519 207.175.226.26 (26 Aug 2003 12:01:59 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail