BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TIdSync get variable from main thread

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri May 04, 2007 7:41 pm    Post subject: TIdSync get variable from main thread Reply with quote



Hello,

How to get data from main thread using TIdSync class? Sample I found does
not return any information back. And it doesn't looks thread safe to add
ReturnInfo variable and read information from it after Write method called.

type
TLogSync = class(TIdSync)

ReturnInfo: String;
private
fDirection: String;
fLine: String;
fIPAddress: String;
procedure DoSynchronize; override;
public
procedure Write(const ADirection, ALine, AIPAddress:
String);
end;


procedure TLogSync.DoSynchronize;
begin
// write fDirection, fLine, and fIPAddress to TRichEdit as
needed...

ReturnInfo:=.
end;


procedure TLogSync.Write(const ADirection, ALine, AIPAddress:
String);
begin
fDirection := ADirection;
fLine := ALine;
fIPAddress := AIPAddress;
Synchronize;
end;
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri May 04, 2007 10:10 pm    Post subject: Re: TIdSync get variable from main thread Reply with quote



<column.column (AT) gmail (DOT) com> wrote in message
news:463b462d (AT) newsgroups (DOT) borland.com...

Quote:
it doesn't looks thread safe to add ReturnInfo variable and
read information from it after Write method called.

Yes, it is, because the worker thread will not be accessing the
ReturnInfo until after DoSynchronize() has exited, so the main thread
won't be using it anymore by that time.

Quote:
procedure TLogSync.DoSynchronize;
begin
// write fDirection, fLine, and fIPAddress to TRichEdit as
needed...
ReturnInfo:=.
end;

You can access your necessary data the same way you are accessing the
TRichEdit. If you have a pointer to your form, then you can access
its members normally.


Gambit
Back to top
Guest






PostPosted: Sat May 05, 2007 8:10 am    Post subject: Re: TIdSync get variable from main thread Reply with quote



I know how to get ReturnInfo from main form - I use procedure pointer that
returns value to ReturnInfo.

procedure TLogSync.DoSynchronize;
begin
if assigned (ProceedRequest) then
TProceedRequest(ProceedRequest)(ReturnInfo,...);
end;


Is it good do like this:

procedure TPOS_TCP.AserverSocketExecute(AContext: TIdContext);
var
mystring:string
begin
LogSync:=TLogSync.Create;
LogSync.ProceedRequest:=ProceedRequestThr;
LogSync.write(....);

mystring:= LogSync.ReturnInfo; //I don't like this
....
LogSync.free;
end;
Back to top
Guest






PostPosted: Sat May 05, 2007 6:40 pm    Post subject: Re: TIdSync get variable from main thread Reply with quote

Quote:
Is it good do like this:

procedure TPOS_TCP.AserverSocketExecute(AContext: TIdContext);
var
mystring:string
begin
LogSync:=TLogSync.Create;
LogSync.ProceedRequest:=ProceedRequestThr;
LogSync.write(....);

mystring:= LogSync.ReturnInfo; //I don't like this
...
LogSync.free;
end;

looks it is not safe to do like this because sometimes i have nonsens in
ReturnInfo.

Question: How to get data from main thread using TIdSync in
TidTCPserver.AserverSocketExecute(AContext: TIdContext);
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon May 07, 2007 10:18 pm    Post subject: Re: TIdSync get variable from main thread Reply with quote

<column.column (AT) gmail (DOT) com> wrote in message
news:463c34cb$1 (AT) newsgroups (DOT) borland.com...

Quote:
mystring:= LogSync.ReturnInfo; //I don't like this

Why not? It works fine.


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon May 07, 2007 10:20 pm    Post subject: Re: TIdSync get variable from main thread Reply with quote

<column.column (AT) gmail (DOT) com> wrote in message
news:463c8969 (AT) newsgroups (DOT) borland.com...

Quote:
looks it is not safe to do like this

Yes, it is safe. DoSynchronize() is called in the context of the main
thread, not the worker thread. The worker thread will not be
accessing ReturnInfo until after DoSynchronize() has fully exited.

Quote:
because sometimes i have nonsens in ReturnInfo.

Then you are doing something else wrong in your other code. The
TIdSync code itself that you have shown so far is fine.

Quote:
How to get data from main thread using TIdSync in
TidTCPserver.AserverSocketExecute(AContext: TIdContext);

You already know the answer to that, because you are already doing it.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.