Ver Mensaje Individual
  #7  
Antiguo 24-09-2013
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Reputación: 20
cesarsoftware Va por buen camino
Cita:
Empezado por gatosoft Ver Mensaje
Creo, (y supongo que es evidente) que el problema se da por la transformación de un texto desde UTF8 a ASCII... estas transportando, cargando un texto que VES en ASCII pero que te ha sido entregado en otro formato... tu lo recibes en ASCII y lo tratas como ASCII... y todo tu codigo está pensado en ASCII...

A mi me sucedia algo parecido, al crear un documento de TEXTO en Notepad++... Cuando lo leia en Delphi con un TStringList me mostraba éstos carateres extraños...

Código Delphi [-]Var Cadena:String; MyStringList.LoadFromFile(NombreArchivo); Cadena:= MyStringList.Text;


lo que sucedía era que el archivo se estaba guardando en UTF8.. para esto Delphi da una solución

Código Delphi [-]Var Cadena:String; MyStringList.LoadFromFile(NombreArchivo,TEncode.UTF8); Cadena:= MyStringList.Text;


Y listo..!!

A pesar que las variables String aceptan por defecto (ahora) carcateres unicode, el TStringList le estaba enviando algo que creia era ASCII...

saludo,
Algo asi debe ser, pero .... este es el código de la función que uso (pero también está este problema EN TODO DELPHI 2010).
Por cierto, uso asnsistring porque cada caracter es de 8 bit, si uso string cada carácter es de 16 bit, que ya me las he tenido que ver con Delphi 2010 por este tema.
Código Delphi [-]
function ThreadReadServidor.Envia(cadena: ansistring): integer;
var
  size: word;
  Resultado, sendlen, slen: integer;
begin
  slen := Sizeof(remoto);
  Resultado := 0;
  size := Length(cadena);
  if size = 0 then
  begin
    Result := -6;
    Exit;
  end;
  if tipo = UDP then
    sendlen := SendTo(nSocket, cadena[1], size, 0, remoto, slen)
  else
    sendlen := Send(nSocket, cadena[1], size, 0);
  if (sendlen = SOCKET_ERROR) or (sendlen < size) then
  begin
    case WSAGetLastError of
      WSANOTINITIALISED: ErrorString := 'A successful WSAStartup call must occur before using this function.';
      WSAENETDOWN: ErrorString := 'The network subsystem has failed.';
      WSAEACCES: ErrorString := 'The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt with the SO_BROADCAST socket option to enable use of the broadcast address.';
      WSAEINTR: ErrorString := 'A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall.';
      WSAEINPROGRESS: ErrorString := 'A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.';
      WSAEFAULT: ErrorString := 'The buf parameter is not completely contained in a valid part of the user address space.';
      WSAENETRESET: ErrorString := 'The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.';
      WSAENOBUFS: ErrorString := 'No buffer space is available.';
      WSAENOTCONN: ErrorString := 'The socket is not connected.';
      WSAENOTSOCK: ErrorString := 'The descriptor is not a socket.';
      WSAEOPNOTSUPP: ErrorString := 'MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.';
      WSAESHUTDOWN: ErrorString := 'The socket has been shut down; it is not possible to send on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.';
      WSAEWOULDBLOCK: ErrorString := 'The socket is marked as nonblocking and the requested operation would block.';
      WSAEMSGSIZE: ErrorString := 'The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.';
      WSAEHOSTUNREACH: ErrorString := 'The remote host cannot be reached from this host at this time.';
      WSAEINVAL: ErrorString := 'The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.';
      WSAECONNABORTED: ErrorString := 'The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.';
      WSAECONNRESET: ErrorString := 'The virtual circuit was reset by the remote side executing a hard or abortive close. For UDP sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a "Port Unreachable" ICMP packet.';// The application should close the socket as it is no longer usable.';
      WSAETIMEDOUT: ErrorString := 'The connection has been dropped, because of a network failure or because the system on the other end went down without notice.';
    else
      ErrorString := 'Error Desconocido';
    end;
    Resultado := -7;
  end;
  Result := Resultado;
end;
__________________
Disfruta de la vida ahora, vas a estar muerto mucho tiempo.
Responder Con Cita