AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

$0 in stream and loading as text

Ein Thema von WojTec · begonnen am 24. Aug 2014 · letzter Beitrag vom 25. Aug 2014
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Re: AW: Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:21
Oh, you are in a bigger trouble than I thought. You should have seen d and not D.
So maybe yor compiler or compter is broken ... sorry to tell that
Probably I see d, not D
Anyway don't working annd changing encoding don't want to help
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Re: AW: Re: AW: $0 in stream and loading as text

  Alt 24. Aug 2014, 14:32
Oh, you are in a bigger trouble than I thought. You should have seen d and not D.
So maybe yor compiler or compter is broken ... sorry to tell that
Probably I see d, not D
Anyway don't working annd changing encoding don't want to help
Maybe you get now the point about "be more precise"
It is near to impossible to help if you tell us about something like.

The source did not contain a whole text but a bunch of strings in a kind of structure. You have to work on that structure and read the data following the structure rules.

A good starting point is to look at the producer of the data and get some information. We do not have (because you did not tell us - another precise mark) any clue about the producer.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
brechi

Registriert seit: 30. Jan 2004
823 Beiträge
 
#3

AW: $0 in stream and loading as text

  Alt 25. Aug 2014, 13:31
You have to write your own component to visualize the text.
Internal PAnsiChar/PWideChar is used and a #0 is the end of the text.

So if you use

Code:
  Memo1.Lines.Text := 'test1'#0'test2'#0;
only the "test1" will be shown.

If you dont want to save your data, then you can load the file into a TMemoryStream (or a string) and replace the #0 with another character.


Code:
var
  s: String;
  fm: TFileStream;
fm := TFileStream.Create;
fm.LoadFromFile('sadasd', fmOpenRead);
setLength(s, fm,size);
fm.Read(s[1], Length(s));
s := StringReplacte(s, #0, #1, [rfReplaceAll]);
memo1.lines.text := s;
etc.
  Mit Zitat antworten Zitat
Benutzerbild von jaenicke
jaenicke
Online

Registriert seit: 10. Jun 2003
Ort: Berlin
9.932 Beiträge
 
Delphi 12 Athens
 
#4

AW: $0 in stream and loading as text

  Alt 25. Aug 2014, 13:45
If you dont want to save your data, then you can load the file into a TMemoryStream (or a string) and replace the #0 with another character.
This is only unicode text, so the problem is not to replace those bytes, but to read the file with correct encoding.
If one did it this way and there is only one real unicode character inside, one would get really strange results...

Even if there is no byte order mark this code works perfectly for me:
Delphi-Quellcode:
var
  test: TStringStream;
begin
  test := TStringStream.Create('', TEncoding.Unicode);
  try
    test.LoadFromFile('c:\temp\a.txt');
    ShowMessage(test.DataString);
  finally
    test.Free;
  end;
end;
So it would be better, if you would attach a working sample code with an example file...
Sebastian Jänicke
AppCentral
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#5

Re: $0 in stream and loading as text

  Alt 25. Aug 2014, 17:06
@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 ), 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;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz