Hola.
Me estuve leyendo el fragmento que esta en ingles pues casualmente soy uno de los que tiene el problema con el caracter #0.
Me estaba ocurriendo que cuando leia el archivo con
LoadFromFile
y dicho archivo contenia en algun lugar el caracter #0 se me cortaba ahi el archivo no seguia cargando.
Quizas la solucion del problema le sea util a alguien y aqui se las dejo.
En el fuente solamente lo que hice fue cambiar el caracter #0 que venia por un caracter A, quizas en otras aplicaciones se deba hacer otra cosa pero creo que el ejemplo vale.
Código Delphi
[-]
unit UCustomTStrings;
{$R-,T-,X+,H+,B-}
{$IFDEF MSWINDOWS}
{$ENDIF}
{$IFDEF LINUX}
{$DEFINE _WIN32}
{$ENDIF}
{$IFDEF MSWINDOWS}
{$DEFINE _WIN32}
{$ENDIF}
interface
{$IFDEF MSWINDOWS}
uses Windows, Messages, SysUtils, Variants, TypInfo, ActiveX, classes;
{$ENDIF}
{$IFDEF LINUX}
uses Libc, SysUtils, Variants, TypInfo, Types, classes;
{$ENDIF}
type
TCustomTStrings = class(TStringList)
Public
procedure LoadFromStream(Stream: TStream);Virtual;
procedure LoadFromFile(const FileName: string);Virtual;
end;
implementation
uses strutils;
procedure TCustomTStrings.LoadFromFile(const FileName: string);
var
Stream: TStream;
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
LoadFromStream(Stream);
finally
Stream.Free;
end;
end;
procedure TCustomTStrings.LoadFromStream(Stream: TStream);
var
Size: Integer;
S : string;
i: integer;
StringSize : integer;
begin
BeginUpdate;
try
Size := Stream.Size - Stream.Position;
SetString(S, nil, Size);
Stream.Read(Pointer(S)^, Size);
StringSize := Length(S);
for i:= 1 to StringSize do
Begin
if S[i] = #0 then S[i] := 'A'; end;
SetTextStr(S);
finally
EndUpdate;
end;
end;
end.
Ah y la llamada y creacion del nuevo componente muy facil.
Código Delphi
[-]
var
tsArchivo : TCustomTStrings;
Begin
tsArchivo := TCustomTStrings.create;
tsArchivo.LoadFromFile(LoteFileName);
Otra variante pudo ser redefinir el metodo
SetTextStr
en lugar de loadfromstream
Por cierto he cargado archivos de mas de 100MBytes con ese codigo
Espero que sea de utilidad a alguien.
Saludos
Juan Carlos