Autor Beitrag
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Fr 01.12.06 19:38 
Hallo,

ich arbeite momentan mal wieder mit Threads, speziell mit BeginThread. Nun möchte ich beim Start einen Parameter mit übergeben, laut msdn etc. sollte das eigentlich auch gehen, aber bei mir kommt der Parameter nur als 0 (also nil) an. Sieht einer von euch den Fehler?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure StartDrawThread(var CurClassList: PClassList);
begin
  CurClassList^.DrawClass._Run //CurClassList ist hier komischerweise nil
end;

function StartDrawing(EngineID: Integer): Integer;
var
  p : PClassList;
  dummy: Cardinal;
begin
  p:=GetEnginePointer(EngineID);
  if p=nil then Result:=SBVE_Err_EngineID_Not_Found
  else
  begin
    Result:=SBVE_No_Errors;
    BeginThread(nil, 0, @StartDrawThread, p, 0, dummy);
  end;
end;
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Fr 01.12.06 21:56 
Liegt wohl an der Deklaration von der Funktion. So gehts:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function ThreadFunc(Parameter: Pointer): Integer;
begin
  MessageBox(0, Pchar(IntToStr(Integer(Parameter^))), '', MB_OK);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Id: Cardinal;
  P: PInteger;
begin
  New(P);
  P^ := 10;
  BeginThread(nil, 0, ThreadFunc, P, 0, Id);
end;
Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Heiko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 02.12.06 09:07 
Ne, es geht auch ohne Funktion. Es lag daran, dass ich "var" oben drin stehen hatte ;).