Ver Mensaje Individual
  #28  
Antiguo 16-06-2014
Avatar de jafera
jafera jafera is offline
Miembro
 
Registrado: may 2007
Ubicación: Llagostera (Girona)
Posts: 582
Reputación: 18
jafera Va por buen camino
Más avances.

Si codifico el txt como UTF8 (guardar como) es cuando detecta los caracteres iniciales.
Si lo codifico Annsi, no me reconoce caracteres al inicio y la linea (Registro) se ve correcta, pero el código no hace sl.Add, peta y da access violation

Codigo modificado:

Código Delphi [-]
begin
           if opendialog1.Execute then
           begin
           AssignFile(Datos,  OpenDialog1.FileName);
           Reset(Datos);
           CaracteresIgnorar := 0;
           PrimeraLinea:=True;
           sl:=TStringList.Create;  // faltaba esto
           try
              while not EOF(Datos) do
              begin
                 ReadLn(Datos, Registro);
                 {En la primera linea debo ver si es un archivo UTF y ver cuantos caracteres debo ignorar}
                 if (PrimeraLinea) then
                 begin
                    if (Ord(Registro[1]) = $EF) and (Ord(Registro[2]) = $BB) and (Ord(Registro[3]) = $BF) then {Posiblemente UTF8}
                       CaracteresIgnorar := 3;

                    Registro := copy(Registro,CaracteresIgnorar, Length(Registro));
                 end;
                 // Agrego Registro a un StringList
                 sl.Add(Registro);                     //Aqui acces violation.
                 next;
              end; // while
              // Grabo el StringList a un fichero Temporal
              sl.SaveToFile('C:\Rebuts_1.0\Fitxers\Ranking\FicheroTemporal.txt');
              finally
              // importo el fichero temporal
              end;
           end;
end;

No se si todo el código de pruebas esta correctamente realizado.
Esta variable sl se debe inicializar?
Por esto da access violation?

Saludos

Josep

Última edición por jafera fecha: 16-06-2014 a las 18:26:33.
Responder Con Cita