Is it safe for two separate TThreads to access a TStringList (one puts the
string in, the other takes it out)??
There are no VCL calls in either thread, and it seems to work ok.
CPB version 6.
Many thanks,
Denville.
HTH Pete
This is the simple code skeleton, which you have
to adjust for your needs.
--- H ---
class TForm1 : public TForm
{
// ...
private: // User declarations
CRITICAL_SECTION MyCriticalSection;
};
class CSLock
{
public:
LPCRITICAL_SECTION fcs;
CSLock( LPCRITICAL_SECTION acs ) : fcs( acs )
{ if ( fcs ) EnterCriticalSection( fcs ); }
~CSLock()
{ if ( fcs ) LeaveCriticalSection( fcs ); }
};
--- CPP ---
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
InitializeCriticalSection( &MyCriticalSection );
}
__fastcall TForm1::~TForm1()
{
DeleteCriticalSection( &MyCriticalSection );
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CSLock lock( &MyCriticalSection );
// Here you can do something with string lists
ShowMessage("DoSomethingWithStringList()");
}
--
Best regards,
Vladimir Stefanovic
"Denville Longhurst" <Denv...@metco.co.uk> wrote in message
news:4225...@newsgroups.borland.com...
Thanks for the quick response and the advice.
Sincerely,
Denville.
"Pete Fraser" <pete.no.s...@frasersoft.nospam.net> wrote in message
news:4225d6e8$1...@newsgroups.borland.com...
Thank you very much for the quick response and the help.
Sincerely,
Denville.
"Vladimir Stefanovic" <anti...@po.sbb.co.yu> wrote in message
> Is it safe for two separate TThreads to access a TStringList
> (one puts the string in, the other takes it out)??
If you not synchronizing access to the TStringList, then no, it is not safe.
> There are no VCL calls in either thread, and it seems to work ok.
Always provide adequate synchronizing when sharing memory across threads.
Gambit
Sincerely,
Denville.
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:422610a8$1...@newsgroups.borland.com...