Sergei
I'm not sure, but I think the problem is that
Lines.Add function works by sending a message
to the memo control and since you're in a critical
section that message won't get read until you go
noncritical.
One way around this is to create your own user
message (to pass the line to add) and POST (not SEND)
it to the Main form and write a handler for it
in the Main form (that will execute on the main
thread) to find the TMemo control and add the
line.
Or - (perhaps simpler) find out what message
to use to add the line, and then from your thread's
critical section POST that message to the Memo
control directly.
Either way, POSTing it will queue up the line
add so that it can get handled later when your
thread goes noncritical.
-ns
----- Original Message -----
From: "Sergei Stenkov" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Monday, July 16, 2001 8:31 AM
Subject: [DUG]: Accessing Application components
> Hello All,
>
> I have a form with my component on it. The component uses Indy's
IdTCPClient
> and runs series of transactions in threads (not TIdThread but
TThread). For
> testing purposes I need to be able to see the results of communication
> between my client and a TCP/IP server. When I run the following code
on the
> component level it all works fine:
>
> file://TTransactionManager is a non-visual component
> procedure TTransactionManager.DisplayResponse(sResponse: String);
> var
> i : Integer;
> begin
> for i := 0 to Application.MainForm.ComponentCount - 1 do begin
> if Application.MainForm.Components[i] is TMemo then begin
> (Application.MainForm.Components[i] as
TMemo).Lines.Add(sResponse);
> break;
> end;
> end;
> end;
>
> But if I run it within a thread as:
>
> // called from critical section
> procedure TTransactionThread.DisplayResponse;
> var
> i : Integer;
> begin
> for i := 0 to Application.MainForm.ComponentCount - 1 do begin
> if Application.MainForm.Components[i] is TMemo then begin
>
> // slResponse is a private TStringList of a TThread and is
loaded with
> response strings
>
>
TMemo(Application.MainForm.Components[i]).Lines.Add(slResponse[slRespons
e.Co
> unt - 1]);
> break;
> end;
> end;
> end;
>
> then the control never comes back.
> Through debugger I can see memo.lines.Add taking me to Windows unit
and
> saying farewell with the line:
>
> function SendMessage; external user32 name 'SendMessageA';
>
> I suspect it's something to do with the way I try to access form's
controls
> from a thread, but I don't know what could be wrong.
>
> All/any suggestions are welcomed and appreciated.
> Thank you,
> Sergei Stenkov
>
> ----------------------------------------------------------------------
-----
> New Zealand Delphi Users group - Delphi List -
[EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/