Watek jako komponent

0

Czy ktos moglby mi pomoc w rozwiazaniu problemu jakim jest stworzenie komponentu opartego na klasie dziedziczonej TThread. Przykladowy kod komponentu wyglada tak:

unit Myhread;

interface

uses
  SysUtils, Classes;

type
  TMyhread = class(Thread)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Kriss', [TMyhread]);
end;

end.

Problem polega w lini

  TMyhread = class(Thread)

gdyz kompilator wyrzuca mi blad ze nie jest to klasa

TComponent
, oczywiscie nie moge z niej skorzystac gdyz moja klasa TMyThreaddziedziczy metody z klasy watkow TThread

Prosze o jaknajszybsza pomoc w rozwiazaniu tego problemu.

Zgory dziex.

0

No to może

type
  TThreadComponent = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    Thread: TThread;
  published
    { Published declarations }
  end;

procedure Register;
begin
  RegisterComponents('Kriss', [TThreadComponent]);
end;

?

Aha i twój kod ma błąd - TThread nie Thread

0

Jesli chodzi o blad to tak, zauwazylem go, ale nie jest on az tak istotny.

Kiedy probuje zrobic to jak piszesz to wciaz mam jakies problemy tym razem tego typu ze:

[Fatal Error] PingThreadComponent.pas(1): Program or unit 'PingThreadComponent.pas' recursively uses itself ```
0
N00byStance napisał(a)

No to może

type
  TThreadComponent = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    Thread: TThread;
  published
    { Published declarations }
  end;

procedure Register;
begin
  RegisterComponents('Kriss', [TThreadComponent]);
end;

jak już to Thread powinien być w sekcji private a nie public.

Co do

[Fatal Error] PingThreadComponent.pas(1): Program or unit 'PingThreadComponent.pas' recursively uses itself

to po prostu masz coś takiego

Unit1
interface 

uses
  Unit2;
....


Unit2
interface

uses
  Unit1;
....

jeśli musisz w obu unitach odwoływać się do siebie nawzajem to w jednym z nich przenieś to odwołanie to sekcji implementation

1 użytkowników online, w tym zalogowanych: 0, gości: 1