Mam pewnego rodzaju problem: wyskakuje mi error zaraz po zaladowaniu plugina. Najprawdopodobniej jest to spowodowane watkiem a ze jestem poczatkujacy w pisaniu pluginow do tego programu to prosze o pomoc

Oto kodzik (troche dlugi mam nadzieje ze mi moderatorzy wybacza ;P )

library plug2;

{$R *.res}

uses
  Windows,
  Plugin_Options,
  Plugin_Struct,
  Plugin_ContactList_Defs,
  SysUtils,
  strona in 'strona.pas' {OptionForm};

{$E tpl}

var
  OptionForm: TOptionForm = nil;
  UchwytSekcji: Integer = 0;
  UchwytElementu: Integer = 0;
  UchwytGrupy: Integer = 0;
  hThread: THandle = 0;
  KoniecWatku: Boolean = False;

  Tlen_Functions: PTlenPluginFunctions;
  PluginInfo: TlenPluginInfo = (
    StructSize           : SizeOf(TlenPluginInfo);
    PluginName           : 'Plug2';
    PluginAPIVersion     : PLUGIN_API_VERSION;
    PluginVersion        : $01020304;
    PluginDescription    : 'Moj pierwszy plugin do tlena =P';
    PluginCopyright      : '(c) none =P';
    PluginAuthor         : 'autor';
    PluginAuthorEmail    : 'E@mail';
    PluginAuthorHomepage : 'http://www';
    Reserved1            : 0;
    Reserved2            : 0;
    Reserved3            : 0;
    Reserved4            : 0
  );

function GetPluginInfo(TlenVersion: DWORD): PTlenPluginInfo; cdecl;
begin
  Result:=@PluginInfo;
end;

function OptionPageClicked(_wParam: WPARAM; lParam: LPARAM): Integer; cdecl;
var
  Info: ^TlenOptionPageShowInfo;
begin
  Info:=Pointer(_wParam);
  StrCopy(Info.Caption, 'Przykładowa nazwa zakładki');
  StrCopy(Info.Description, 'To jest opis zakładki, tutaj można wstawić dłuższy tekst, aby wyjaśnić 

użytkownikowi, co się tu dzieje.');

  case (Info.Action) of
    TLEN_OPTIONS_PAGE_ACTION_SHOW:
      begin
        if OptionForm = nil then
        begin
          OptionForm := TOptionForm.Create(nil);
          OptionForm.ParentWindow := Info.Handle;
          tlen_functions.CallTlenFunction(hInstance, TLEN_ADD_DIALOG_HANDLE, WPARAM(OptionForm.Handle), 0);
        end;

        OptionForm.SetBounds(info.x, info.y, info.width, info.height);
        OptionForm.Visible := True;
      end;
    TLEN_OPTIONS_PAGE_ACTION_HIDE:
        if OptionForm <> nil then
           OptionForm.Visible := False;
    TLEN_OPTIONS_PAGE_ACTION_APPLY,
    TLEN_OPTIONS_PAGE_ACTION_OK:
      begin
        //Kliknięto ok, wiŕc przetwarzamy tutaj opcje wybrane przez użytkownika
      end;
    TLEN_OPTIONS_PAGE_ACTION_CANCEL:
      begin
       //Usuwamy uchwyt okienka z listy i niszczmy je
       if OptionForm <> nil then
       begin
         tlen_functions.CallTlenFunction(hInstance, TLEN_REMOVE_DIALOG_HANDLE, WPARAM(OptionForm.Handle), 0);
         OptionForm.Free;
         OptionForm := nil;
       end;
      end;
  end;
  Result:=0;
end;

function RedrawThreadFunc(lpParam: Pointer): DWord; cdecl;
var
  Item: PContactListItemDef;
begin
  while not KoniecWatku do
  begin
    Sleep(100);
    if KoniecWatku then Break;

    FillChar(Item, SizeOf(Item), 0);
    Item.structSize := SizeOf(Item);
    Item.MainText := PAnsiChar(DateTimeToStr(now));
    Item.ItemHint := PAnsiChar(DateTimeToStr(now));

    Item.ChangeFlags := CONTACTLIST_ITEMCHANGEFLAG_MAINTEXT or CONTACTLIST_ITEMCHANGEFLAG_REDRAWITEM;

    Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_CHANGEITEM, WPARAM(UchwytElementu), 

LPARAM(@Item));
  end;

  Result:=0;
end;

function LoadPlugin(Functions: PTlenPluginFunctions): Integer; cdecl;
var
  TlenOP: TlenOptionPageDefinition;
  Item: ContactListItemDef;
  dwThreadID: DWORD;
begin
  Tlen_Functions := Functions;

  TlenOP.structSize := SizeOf(TlenOp);
  TlenOP.CallBack := OptionPageClicked;
  TlenOP.ID := 'michuplug/plug1';
  TlenOP.Caption := 'MichuPlug1';
  TlenOP.Position := 0;

  Tlen_Functions.CallTlenFunction(hInstance, TLEN_ADD_OPTIONS_PAGE, WPARAM(hInstance), LPARAM(@TlenOP));

  // tworzenie sekcji

  FillChar(Item, SizeOf(Item), 0);
  Item.structSize := SizeOf(ContactListItemDef);
  Item.ItemKind := CONTACTLIST_ITEMKIND_SECTION;
  Item.Flags1 := CONTACTLIST_ITEMFLAG1_EXPANDED or CONTACTLIST_ITEMFLAG1_EXPANDABLE or
                 CONTACTLIST_ITEMFLAG1_CHILDRENVISIBLE;

  Item.MainText := 'Ile jeszcze';
  Item.PreviousItemHandle := CONTACTLIST_ITEMPOS_FIRST;

  if Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_ADDITEM, WPARAM(@Item), 0) = 0 then
     UchwytSekcji := Item.itemHandle;

  // end - tworzenie sekcji

  //Dodajemy grupę "Przykładowa grupa"
  FillChar(item, SizeOf(item), 0);
  item.structSize:=SizeOf(ContactListItemDef);
  item.ItemKind:=CONTACTLIST_ITEMKIND_GROUP;
  item.Flags1:=CONTACTLIST_ITEMFLAG1_EXPANDED or
                CONTACTLIST_ITEMFLAG1_EXPANDABLE;

  item.MainText:='Przykładowa grupa';
  item.SectionHandle:=UchwytSekcji;

  if tlen_functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_ADDITEM, WPARAM(@item), 0)=0 then
    UchwytGrupy:=item.ItemHandle;

  // tworzenie itema

  FillChar(Item, SizeOf(Item), 0);
  Item.structSize := SizeOf(Item);

  Item.SectionHandle := UchwytSekcji;
  Item.GroupHandle := UchwytGrupy;

  Item.ItemKind := CONTACTLIST_ITEMKIND_ELEMENT;

  Item.MainText := 'dupa ;)';
  Item.ItemHint := 'dupa hint';

  if Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_ADDITEM, WPARAM(@Item), 0)=0 then
    UchwytElementu := Item.ItemHandle;

  // end - tworzenie itema

  hThread := CreateThread(nil, 0, @RedrawThreadFunc, nil, 0, dwThreadId);

  Result:=0;
end;

function UnloadPlugin: Integer; cdecl;
begin
  if (OptionForm <> nil) then
  begin
    Tlen_Functions.CallTlenFunction(hInstance, TLEN_REMOVE_DIALOG_HANDLE, WPARAM(OptionForm.Handle), 0);
    OptionForm.Free;
  end;

  KoniecWatku := True;
  if hThread <> 0 then WaitForSingleObject(hThread, Infinite);

  Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_REMOVEITEM, WPARAM(UchwytElementu), 0);
  Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_REMOVEITEM, WPARAM(UchwytGrupy), 0);
  Tlen_Functions.CallTlenFunction(hInstance, TLEN_CONTACTLIST_REMOVEITEM, WPARAM(UchwytSekcji), 0);

  Result:=0;
end;

exports
  GetPluginInfo,
  LoadPlugin,
  UnloadPlugin;

begin
end.

z gory dzieki