[DUG] AV problem in a thread object

Matt Comb matt at ferndigital.com
Wed Sep 28 19:13:44 NZST 2005


Its been a while since I have worked with midware, but accessing a non 
threadsafe property from a thread is generally not a good idea.

What about giving the ServerObject a property such as ResponseText that is 
encased in a critical section. The worker thread could write to this in the 
properties write method, you could write the response to the midware buffer 
?

Matt.

----- Original Message ----- 
From: "Grant Brown" <grant at sitedoc.com.au>
To: "Delphi List - Australia" <adug-members at adug.org.au>; "Delphi List - NZ" 
<delphi at ns3.123.co.nz>; "Midware support mailing list" <midware at elists.org>
Sent: Wednesday, September 28, 2005 4:57 PM
Subject: [DUG] AV problem in a thread object


> Hi all,
>
> Using Delphi 5 and Midware components
>
> I keep getting an AV when trying to access the Response Buffer from a 
> thread. I have listed the relevant parts of the code below.
>
> Could anyone have a look and tell me what the problem is.
>
> TIA
>
> Regards
> Grant Brown
>
> ----------- Code snippets ---------------
>
> #### the threads excute method
>
> procedure TServerThreadObj.Execute;
> begin
>    while not terminated do
>    begin
>     FResponseBuffer.Rewrite; #### AV at this point
>
> ##### the actual thread object class
>
> type
>  TServerThreadObj = class(TThread)
>  private
>  protected
>  public
>    FResultStatus: ^Integer;
>    FResponseBuffer: TMWBuffer;
>    UserDataPointer: Integer;
>    OwnerHandle: Integer;
>    procedure Execute; override;
>  published
>  end;
>
> #### Part of the Server Object class
>
>  private
>    FWorkerThread: TServerThreadObj;
>    FWindowHandle: Integer;
>    procedure WMFinish(var msg: TMessage); message WM_FINISH;
>    procedure WndProc(var MsgRec: TMessage); virtual;
>
> #### the server object excute method
>
> procedure TServerObjectSENDLIST_USER_FULL.Execute;
> begin
>  ResponseBuffer.Rewrite;
>  FWorkerThread := TServerThreadObj.Create(TRUE);
>  FWorkerThread.UserDataPointer := Self.UserData;
>  FWorkerThread.FResponseBuffer := TObject(ResponseBuffer) as TMWBuffer;
>  FWorkerThread.FResultStatus := @ResultStatus;
>  FWorkerThread.OwnerHandle := FWindowHandle;
>  FWorkerThread.FreeOnTerminate := TRUE;
>  FWorkerThread.Resume;
> end;
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.344 / Virus Database: 267.11.8/113 - Release Date: 27/09/2005
> 



More information about the Delphi mailing list