Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Not and EDB issue but I thought I'd start here..
Thu, Aug 16 2018 7:49 PMPermanent Link

Ian Branch

Avatar

Hi Guys,
   I'm converting an old component library from Utilmind from D2007 to D10.2.3.
   Going OK but stuck at the following piece of code..
{code}
constructor TdcEventThread.Create(aOwner: TdcCustomThread);
begin
 inherited Create;
 Owner := aOwner;

 AddThread;

 FSuspended := True; // always suspended after creation
 FHandle := BeginThread(nil, 0, @ThreadProc, Pointer(Self), CREATE_SUSPENDED, FThreadID);
end;
{code}
   I get the following message for the FHandle := line...

   "[dcc32 Error] dcThread.pas(317): E2033 Types of actual and formal var parameters must be identical"

   Threading has never been my thing and I can't tell which element is incorrect.

   @ThreadProc returns a System.Integer, Pointer(Self) rewturns a System.Pointer, CREATE_SUSPENED returns a Constant,
FThreadID a System.Cardinal.

   Any thoughts/suggestions appreciated.
Regards,
Ian
Fri, Aug 17 2018 2:39 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


I assume its the same in D2006 & D2007 so

D2006 (from OLH)
BeginThread(SecurityAttributes: Pointer; StackSize: Cardinal; ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: Cardinal; var ThreadId: Cardinal): Integer;

XE (from embarcadro on-line manual)
BeginThread(SecurityAttributes: Pointer; StackSize: LongWord; ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord; var ThreadId: TThreadID): THandle;


Your's
BeginThread(nil, 0, ThreadProc, Pointer(Self), CREATE_SUSPENDED, FThreadID);

So

SecurityAttributes - looks OK
StackSize - looks OK
ThreadFunc - looks OK
Parameter - looks OK
CreationFlags - should be OK since you're using a predefined constant
ThreadId - this looks like the one, even if  type TThreadID = Cardinal;

Its entirely its possible I'm wrong though

Roy Lambert
Fri, Aug 17 2018 3:53 AMPermanent Link

Ian Branch

Avatar

Hi Roy,
   Thanks for looking.
   FThreadID is defined in TdcEventThread..
{code}
 { TdcEventThread }
 TdcEventThread = class
 private
   FHandle: THandle;      <<<  System.Cardinal
   FThreadID: THandle;
   FTerminated: Boolean;
....
....
{code}

   Then used for a public property ThreadID..
{code}
   property ThreadID: THandle read FThreadID;
{code}
   for TdcEventThread.

   Hmmmm.
Ian
Fri, Aug 17 2018 3:58 AMPermanent Link

Matthew Jones

Ian Branch wrote:

>  Types of actual and formal var parameters must be identical"

My first thought matched Roy - it is the FThreadID because that's the only var there. But if that is right, then it is in the definition of your ThreadProc, as that presumably has a var in it?

--

Matthew Jones
Fri, Aug 17 2018 5:21 AMPermanent Link

Ian Branch

Avatar

Hi Matthew,

{code}
function ThreadProc(Thread: TdcEventThread): Integer;
var
 FreeThread: Boolean;
begin
 if Thread.FTerminated then // never executed but terminated
  begin
   FreeThread := Thread.FFreeOnTerminate;
   Result := Thread.FReturnValue;
   if FreeThread then Thread.Free;
   EndThread(Result);
  end
 else
  begin
   Thread.FRunning := True;
   try
     Thread.Execute;
   finally
     FreeThread := Thread.FFreeOnTerminate;
     Result := Thread.FReturnValue;
     try
       Thread.DoTerminate;
     finally
       Thread.FRunning := False;
       if FreeThread then Thread.Free;
       EndThread(Result);
     end;
   end;
  end;
end;
{code}
Fri, Aug 17 2018 6:15 AMPermanent Link

Matthew Jones

It's just the prototype that is needed - and that of BeginThread. What is the definition of that in parameter 3?

(Sorry to be lazy, I don't have a VM with such recent Delphi running at the moment)


--

Matthew Jones
Sat, Aug 18 2018 2:52 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian

The only thing I can think of to try and identify the problem is to change each parameter in turn to a constant (eg ThreadProc to nil  and Pointer(Self) to 0) and see if it compiles. When it does you've found the guilty party and, hopefully, can continue.


Roy Lambert
Sat, Aug 18 2018 4:19 AMPermanent Link

Ian Branch

Avatar

Hi Roy, Matthew,
   I think it boils down to FThreadID.  In all others cases from a google search I see the variable used in BeginThread
it is a LongWord.  THandle is an Integer.

   So, I put a var at the start of the constructor..var x: LongWord;, added x := FThreadID; in the code and substituted x
for FThreadID in the BeginThread function.

   It builds. Smile As to if it works, or not will have to wait as there are more pieces of code to change to bring it up
to D10.2.3.

   Thanks for the assist guys.

Regards,
Ian
Image