🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem with Stringlist in service application

#13506
From: Remy Lebeau (TeamB)
Date: Sat, 11 Oct 2003 07:19
86 lines
3884 bytes
"Victor G. Baron" <vgbaron@hotmail.com> wrote in message
news:18afov85hscnd8n1qjjh41bqgceis3cb0i@4ax.com...

> The bulk of this code was copied from the Using Threads example
> in the Helpfile for TServiceApplication. I can't answer for why they
> set it up that way.

Because Borland's examples are hardly ever very accurate.  Sometimes they
don't realize they are writing examples on top of their own bugs.

> The delete is outside the while loop.

It was hard to tell in your previous message, you put your "thank you" in
the middle of your code, but it definately did look like you are calling
'delete' inside the loop before calling Sleep().  Can you verify that it
really is *outside* the loop?  What does the code look like without the
"thank you" getting in the way?

> I've moved stuff around trying different things but this is back
> to the original way.
>
> I've stripped out everything except the code that crashes.

From what you have described earlier, and what I have suggested, the thread
code should look something like this:

    class TConvThread : public TThread
    {
    protected:
        void __fastcall AfterConstruction();
        void __fastcall Execute();
    public:
        __fastcall TConvThread();
        __fastcall ~TConvThread();

        TStringList* inputfile;
        String input_file;
        String output_file;
    };

    __fastcall TConvThread::TConvThread()
        : TThread(true)
    {
        inputfile = new TStringList;
        inputfile->Sorted = true;

        input_file ="C:\\auth_user_file.txt";
        output_file =
"H:\\Borland\\CBuilder5\\Projects\\VPC_CONV\\onlineusers.txt";
    }

    __fastcall TConvThread::~TConvThread()
    {
        delete inputfile;
    }

    void __fastcall TConvThread::AfterConstruction()
    {
        Resume();
    }

    void __fastcall TConvThread::Execute()
    {
        while( !Terminated )
        {
            //...
            inputfile->LoadFromFile(input_file);
            //..
            Beep();

            // loop the sleeping so that the thread is not blocked
            // sleeping for 10 minutes in case the application needs
            // to stop the thread, such as during program shutdown,
            // so that the thread can stop sleeping and terminate in a
            // timely fashion..  The alternative is to use CreateEvent()
            // and WaitForSingleObject() instead of Sleep() and have
            // the application signal the event to "wake up" the thread.

            for(int x = 0; (x < 600) && (!Terminated); ++x)
                Sleep(1000);
        }
    }


Gambit
Technical Details
Message-ID: <3f87ae6e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <ppueovg2k6grk500sgq49urri491tltrk7@4ax.com> <3f87807f$1@newsgroups.borland.com> <rn2fovgubqp92b3gv6te6rhj7kh0ih4p30@4ax.com> <3f8791ec@newsgroups.borland.com> <525fovoj0ltdsbhpo7vo2tsen3nrsa2g1l@4ax.com> <3f87a6b6$1@newsgroups.borland.com> <18afov85hscnd8n1qjjh41bqgceis3cb0i@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,4f6a692a96789751
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-11 00:39:01 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <ppueovg2k6grk500sgq49urri491tltrk7@4ax.com> <3f87807f$1@newsgroups.borland.com> <rn2fovgubqp92b3gv6te6rhj7kh0ih4p30@4ax.com> <3f8791ec@newsgroups.borland.com> <525fovoj0ltdsbhpo7vo2tsen3nrsa2g1l@4ax.com> <3f87a6b6$1@newsgroups.borland.com> <18afov85hscnd8n1qjjh41bqgceis3cb0i@4ax.com>
Subject: Re: Problem with Stringlist in service application
Date: Sat, 11 Oct 2003 00:19:02 -0700
Lines: 88
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.1165
NNTP-Posting-Host: 67.22.137.75
Message-ID: <3f87ae6e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1065856622 67.22.137.75 (11 Oct 2003 00:17:02 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail