Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Suche WSocket unit für D2010 (Unicode) (https://www.delphipraxis.net/177579-suche-wsocket-unit-fuer-d2010-unicode.html)

pertzschc 14. Nov 2013 13:18

Suche WSocket unit für D2010 (Unicode)
 
Hallo zusammen,
wir verwenden in alten D7-Projekten die Unit WSockets.pas von Robert T. Palmqvist:
Delphi-Quellcode:
unit WSockets;
{

WSockets Version 1.20 - A Simple VCL Encapsulation of the WinSocket API

VCL Classes in this Unit:
  TTCPClient - A TCP Client (derived from TCustomWSocket)
  TTCPServer - A TCP Server (derived from TCustomWSocket)
  TUDPClient - A UDP Client (derived from TCustomWSocket)
  TUDPServer - A UDP Server (derived from TCustomWSocket)

Other classes ni this Unit:
  TCustomWSocket - A generic base class for other socket classes
  TClientList   - A list class used only by the TTCPServer class

Legal issues:

Copyright (C) 1997 by Robert T. Palmqvist <robert.palmqvist@skanska.se>
...
Nun möchten wir die Projekte auf Delphi 2010 (Unicode) umstellen und ich bin auf der Suche nach einer neuen Version der Unit. Weiß jemand, ob es eine neue Version gibt?

Danke,
Christoph

Klaus01 14. Nov 2013 13:24

AW: Suche WSocket unit für D2010 (Unicode)
 
..magst Du wsockets.pas nicht selber anpassen.
Im ersten Ansatz string durch ansiString ersetzen.

Welche Fehler bekommst Du denn, wenn Du die Unit benutzt?

Grüße
Klaus

pertzschc 14. Nov 2013 13:30

AW: Suche WSocket unit für D2010 (Unicode)
 
Zitat:

Zitat von Klaus01 (Beitrag 1235858)
..magst Du wsockets.pas nicht selber anpassen.

Ich habe es versucht: PChar -> PAnsiChar und Char -> AnsiChar.

Zitat:

Zitat von Klaus01 (Beitrag 1235858)
Welche Fehler bekommst Du denn, wenn Du die Unit benutzt?

[DCC Fehler] WSockets.pas(909): E2010 Inkompatible Typen: 'Array' und 'PAnsiChar'
bei ->:
Delphi-Quellcode:
function TCustomWSocket.GetLocalHostAddress: string;
var
  SockAddrIn: TSockAddrIn;
  HostEnt: PHostEnt;
  szHostName: array[0..128] of AnsiChar;
begin
-> if gethostname(szHostName, 128) = 0 then
  begin
    HostEnt := gethostbyname(szHostName);
    if HostEnt = nil then
      Result := ''
    else
    begin
      SockAddrIn.sin_addr.S_addr := longint(plongint(HostEnt^.h_addr_list^)^);
      Result := inet_ntoa(SockAddrIn.sin_addr);
    end;
  end
  else
    SocketError(WSAGetLastError);
end;
Gruß, Christoph

Klaus01 14. Nov 2013 13:41

AW: Suche WSocket unit für D2010 (Unicode)
 
und wenn du es so schreibst?

Delphi-Quellcode:
if gethostname(szHostName[0], 128) = 0 then
  begin
Grüße
Klaus

pertzschc 14. Nov 2013 14:09

AW: Suche WSocket unit für D2010 (Unicode)
 
Jetzt habe ich es:
Delphi-Quellcode:
function TCustomWSocket.GetLocalHostAddress: string;
var
  SockAddrIn: TSockAddrIn;
  HostEnt: PHostEnt;
  szHostName: array[0..128] of AnsiChar;
begin
  if gethostname(szHostName, SizeOf(szHostName)) = 0 then
  begin
    HostEnt := gethostbyname(szHostName);
    if HostEnt = nil then
      Result := ''
    else
    begin
      SockAddrIn.sin_addr.S_addr := longint(plongint(HostEnt^.h_addr_list^)^);
      Result := inet_ntoa(SockAddrIn.sin_addr);
    end;
  end
  else
    SocketError(WSAGetLastError);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:08 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