Problems with Thread

Hi i have a litle problem with my thread.
I want to give a parameter to the thread Procedure !

H:=1;
ComThread := CreateThread(nil, 16384, @ComThreadProc, Pointer(H), 0, ComThreadID);


procedure ComThreadProc(H : integer);
begin
    if H <> 1 then H := 1;
    with ComPorts[H] do

H is 0 in the Thread's procedure !
snoopy_SpyAsked:
Who is Participating?
 
EpsylonConnect With a Mentor Commented:
Alright! This is it!

Just use the stdcall directive:

procedure ComThreadProc(H : Integer); stdcall;
begin
  if H = 1 then Beep;
end;

procedure TForm1.Button1Click(Sender: TObject);
var H: Integer;
    ComThread: Cardinal;
    ComThreadID: Cardinal;
begin
  H := 1;
  ComThread := CreateThread(nil, 16384, @ComThreadProc, Pointer(H), 0, ComThreadID);
end;

Eps.
0
 
snoop_doggy_doggCommented:
Kinda gives me the willies...just tried it for myself...listening.
0
 
EpsylonCommented:
Try

ComThread := CreateThread(nil, 16384, @ComThreadProc, @H, 0, ComThreadID);

I think you should treat H in ComThreadProc as a pointer too....

Epsylon.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
snoop_doggy_doggCommented:
Ep, that's what I thought too...but the cast is done automatically.  It still wont work, I bet.
0
 
snoop_doggy_doggCommented:
Whoo hoo!!
0
 
EpsylonCommented:
Does it work now (it does for me). You can accept my comment as the answer if it does.
0
 
snoopy_SpyAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.