Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi $0 in stream and loading as text (https://www.delphipraxis.net/181547-%240-stream-loading-text.html)

WojTec 25. Aug 2014 17:06

Re: $0 in stream and loading as text
 
@Sir Rufo, next time I'll be more precise :)
Data producer is unknown, I just know it is some resource compiler + compiler + linker (mean file is executable). Data is some data, it can be in any format, it can be a string too.

I wrote simple function to check if stream can be Unicode or ANSII:

Delphi-Quellcode:
function GetEncoding(AStream: TStream): TEncoding;
var
  V: Byte;
begin
  Result := TEncoding.ANSI;

  if AStream.Size > 1 then
  begin
    AStream.Position := 1;
    AStream.ReadBuffer(V, 1);
    if V = 0 then
      Result := TEncoding.Unicode
    ;
  end;
end;
Another one, I badly loaded encoded text (LoadFromStream - it was raw data, stupilo :oops:), Append(DataString) is required.

As @brechi told, pointer terminate code is zero in TStrings, so this is main problem. I don't know how jump over it :(

Also I wrote poor (because very slow) procedure to replace bytes in stream, if someone need it:

Delphi-Quellcode:
procedure ReplaceBytes(AIn: TStream; const AFrom, ATo: Byte; AOut: TStream);
var
  I: Cardinal;
  V: Byte;
begin
  for I := 1 to AIn.Size do
  begin
    AIn.ReadBuffer(V, 1);

    if V = AFrom then
      AOut.WriteBuffer(ATo, 1)
    else
      AOut.WriteBuffer(V, 1)
    ;
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:55 Uhr.
Seite 2 von 2     12   

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