🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages Started by column.column Fri, 04 May 2007 14:41
TIdSync get variable from main thread
#1085
Author: column.column
Date: Fri, 04 May 2007 14:41
38 lines
1965 bytes
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;
Re: TIdSync get variable from main thread
#1086
Author: Remy Lebeau (TeamB)
Date: Fri, 04 May 2007 17:10
24 lines
1750 bytes
<column.column@gmail.com> wrote in message
news:463b462d@newsgroups.borland.com...

> 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.

>     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
Re: TIdSync get variable from main thread
#1089
Author: column.column
Date: Sat, 05 May 2007 07:39
24 lines
1526 bytes
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;
Re: TIdSync get variable from main thread
#1091
Author: column.column
Date: Sat, 05 May 2007 13:40
20 lines
1534 bytes
> 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);
Re: TIdSync get variable from main thread
#1095
Author: Remy Lebeau (TeamB)
Date: Mon, 07 May 2007 17:18
10 lines
1169 bytes
<column.column@gmail.com> wrote in message
news:463c34cb$1@newsgroups.borland.com...

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

Why not?  It works fine.


Gambit
Re: TIdSync get variable from main thread
#1094
Author: Remy Lebeau (TeamB)
Date: Mon, 07 May 2007 17:20
22 lines
1732 bytes
<column.column@gmail.com> wrote in message
news:463c8969@newsgroups.borland.com...

> 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.

> 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.

> 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
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