Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Problem: Indy-Thread und Pointer (https://www.delphipraxis.net/137112-problem-indy-thread-und-pointer.html)

J_e_n_s 14. Jul 2009 17:03


Problem: Indy-Thread und Pointer
 
Hallo,

ich habe folgendes Problem, gleich Vorweg, mit Threadprogrammierung kenne ich mich nicht so gut aus, vielleicht kann mir jemand weiterhelfen.

In meinem Delphi7-Programm verwende ich eine DLL für Bildverarbeitung, welche über ein Handle gestartet wird und auch wieder beendet wird.

Es gibt nun 2 Buttons auf der Programmoberfläche mit denen man die Bildverarbeitung startet bzw beendet --> funktioniert einwandfrei

starten:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  hwnd := Pointer(Form1.Handle);
  withandle := witDLLInit4(hwnd, 0, nil, nil, 0, nil);
end;
beenden:
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
begin
   WitDllExit(withandle);
end;
Desweiteren soll dies auch über TCP/IP-Befehle möglich sein, hierfür verwende ich die Indy-komponenten:

Delphi-Quellcode:
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
    Command : String;
    temp: String;
begin
  Command := AThread.Connection.ReadLn;
  Command := uppercase(Command);
  if (Command = 'LOADDLL') then      [b]//starten[/b]
  begin
         hwnd := Pointer(Form1.Handle);
         withandle := witDLLInit4(hwnd, 0, nil, nil, 0, nil);
         temp:='DLL_LOADED' + chr(10);   
   AThread.Connection.Write(temp);
  end
  else if (Command = 'UNLOADDLL') then      [b]//beenden[/b]
  begin
   WitDllExit(withandle);
   temp:='DLL_UNLOADED' + chr(10);
   AThread.Connection.Write(temp);
  end
  else
  begin
    temp:='NOK:UNKNOWN_COMMAND' + chr(10);
    AThread.Connection.Write(temp);
  end;
end;
--> Auch das funktioniert für sich einwandfrei

D.h. Starten über Button, beenden über Button geht
Starten über TCP/IP, beenden über TCP/IP geht

Jetzt das Problem: Starte ich die DLL über den Button und will Sie über TCP/IP beenden hängt sich das Programm auf, genauso anders herum....

Bin mir ziemlich sicher dass die Pointer nur in ihrem eigenen Thread gültig sind und es deshalb Probleme gibt, finde aber keine verlässliche einfache Lösung dies zu umgehen.

Vielen Dank für Eure Hilfe,
Jens

samso 14. Jul 2009 17:38

Re: Problem: Indy-Thread und Pointer
 
vielleicht funktioniert dies (quick & dirty):

Delphi-Quellcode:
  TForm1
  ....
  private
    withandle: TwitHandle;
    procedure DoCloseWit;
    procedure DoStartWit;
  ...


procedure TForm1.DoCloseWit;
begin
  WitDllExit(withandle);
end;

procedure TForm1.DoStartWit;
begin
  withandle := witDLLInit4(Pointer(Handle), 0, nil, nil, 0, nil);
end;

...

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
    Command : String;
    temp: String;
begin
  Command := AThread.Connection.ReadLn;
  Command := uppercase(Command);
  if (Command = 'LOADDLL') then     [b]//starten[/b]
  begin
    AThread.Synchronize(DoStartWit);
    temp:='DLL_LOADED' + chr(10);  
   AThread.Connection.Write(temp);
  end
  else if (Command = 'UNLOADDLL') then     [b]//beenden[/b]
  begin
   AThread.Synchronize(DoStopWit);
   temp:='DLL_UNLOADED' + chr(10);
   AThread.Connection.Write(temp);
  end
  else
  begin
    temp:='NOK:UNKNOWN_COMMAND' + chr(10);
    AThread.Connection.Write(temp);
  end;
end;
Was ist, wenn mehrere Clients auf den Server zugreifen?

J_e_n_s 14. Jul 2009 18:11

Re: Problem: Indy-Thread und Pointer
 
Hallo Samso,

Es funktioniert!!!! :dancer:

Danke, Du hast meinen Abend gerettet, vielen Dank!! :-D

viele Grüße,
Jens


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz