Autor Beitrag
Passi077
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Fr 13.07.07 18:53 
Hi,

ich beschäftige mich zur Zeit mit Threads. Leider scheitere ich schon beim Konstruktoraufruf..

so sieht meine ThreadKlasse aus:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
unit Unit2;

interface

uses
  Classes, sysutils, StdCtrls;

type
  TDLThread = class(TThread)
  private
    { Private-Deklarationen }
    count: integer;
    GUI: TLabel;
  protected
    procedure Execute; override;
    procedure DoSync;
  protected
    constructor Create(pGUI: TLabel);
  end;

implementation

{ TDLThread }

constructor TDLThread.Create(pGUI: TLabel);
begin
  GUI := pGUI;

  FreeOnTerminate := True;
  inherited Create(False);
end;

procedure TDLThread.Execute;
begin
  { Thread-Code hier einfügen }
 while not terminated do
 begin
  count := count + 1;
  Synchronize(DoSync);
 end;
end;

procedure TDLThread.DoSync();
begin
 GUI.caption := inttostr(count);
end;

end.


Mein Konstruktoraufruf im ButtonKlick der Form wie folgt:

ausblenden Delphi-Quelltext
1:
2:
3:
  setlength(dlthreads, 2);
  dlthreads[0] := tdlthread.Create(label1);
  dlthreads[0].Resume();


Das Problem ist nun, dass er statt meinem Label ein Boolean haben will, "CreateSuspended".

Wer sagt mir, woran das liegt :) ?

Danke + Grüße
Passi
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: Fr 13.07.07 20:52 
Der Fehler liegt hier:

ausblenden Delphi-Quelltext
1:
2:
  protected
    constructor Create(pGUI: TLabel);


Dein Konstruktor ist protected und kann deswegen nicht von aussen aufgerufen werden. Wenn du das in public änderst, sollte es funktionieren.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Fr 13.07.07 21:21 
:roll:

Danke!

Manchmal sieht man die einfachsten Sachen nicht..