Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-11-2017
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Poder: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Prueba con esta versión:
Notarás que hay una variable mas "P2" de tipo PChar.
Quizas la asignación directa del resultado de inet_ntoa que es PChar a String no le gusta.

Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     Result := Result + p2;
     WSACleanup;
  except
     Result := '';
  end;
end;

Estuve leyendo que inet_ntoa devuelve null si ha encontrado un error.
Cita:
De la ayuda de Delphi 6:
The Windows Sockets inet_ntoa function converts a network address into a string in dotted format.

char FAR * inet_ntoa (
struct in_addr in
);


Parameters
[in] A structure which represents an Internet host address.

Remarks
This function takes an Internet address structure specified by the in parameter. It returns an ASCII string representing the address in ".'' notation as "a.b.c.d''. Note that the string returned by inet_ntoa resides in memory which is allocated by Windows Sockets. The application should not make any assumptions about the way in which the memory is allocated. The data is guaranteed to be valid until the next Windows Sockets function call within the same thread, but no longer.

Return Values
If no error occurs, inet_ntoa returns a char pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL. The data should be copied before another Windows Sockets call is made.
Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     if (Assigned(p2)) then
        Result := Result + p2
     else
        Result := '';
     WSACleanup;
  except
     Result := '';
  end;
end;
Responder Con Cita
  #2  
Antiguo 06-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Cita:
Empezado por duilioisola Ver Mensaje
Prueba con esta versión:
Notarás que hay una variable mas "P2" de tipo PChar.
Quizas la asignación directa del resultado de inet_ntoa que es PChar a String no le gusta.

Código Delphi [-]
function DameIPLocal: string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : PChar;
  wVersionRequested : word;
  wsaData : TWSAData;
begin
  // Arranca la librería WinSock
  try
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

     // Obtiene el nombre del PC
     GetHostName(@s, 128);
     p := GetHostByName(@s);

     // Obtiene la dirección IP y libera la librería WinSock
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     if (Assigned(p2)) then
        Result := Result + p2
     else
        Result := '';
     WSACleanup;
  except
    on E: Exception do
      Result := E.Message;
  end;
end;


Le agregue a tu funcion el Mensaje de Excepcion para saber si aun continua y desafortunadamente la Excepcion persiste.
Responder Con Cita
  #3  
Antiguo 06-11-2017
rdaniel2000 rdaniel2000 is offline
Miembro
 
Registrado: jun 2003
Posts: 11
Poder: 0
rdaniel2000 Va por buen camino
Confirmado, Instale Windows Server 2016 Version 1607 (Compilacion de SO 14393.0)

Usando el ISO, sin aplicar ninguna actualizacion de Windows y el Error se presenta al obtener el IP, y ademas de eso muchos otros errores con los componentes de Delphi.

Procedi a Actualizar Windows (KB4035631)

Y con esta actualizacion ya funcionan todas las Funciones anteriores...

Como lo habia dicho, la Instalacion por default de Windows tiene errores que han sido corregidos por Micro$oft.


Saludos,.
Responder Con Cita
  #4  
Antiguo 24-11-2017
Vero190 Vero190 is offline
Registrado
NULL
 
Registrado: nov 2017
Posts: 4
Poder: 0
Vero190 Va por buen camino
Justo lo que necesitaba! Gracias!
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Conexion a servidor dedicado windows server y sql server ValentinoP MS SQL Server 3 23-01-2017 18:14:37
SQL Server 2000 vs Windows Server 2008 Enterprise lgarcia MS SQL Server 9 31-08-2016 19:10:58
Conectar a SQL Server y Windows 2003 Server Punzo MS SQL Server 2 11-12-2007 20:30:40
Windows Media Server e Internet Information Server Ñuño Martínez Windows 0 08-09-2006 11:26:53
Compartir recursos entre Windows Nt Server y Windows 98 fer21unmsm Windows 1 18-07-2006 22:05:44


La franja horaria es GMT +2. Ahora son las 14:13:50.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi