AGB  ·  Datenschutz  ·  Impressum  







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

Broken TBytes

Ein Thema von wil32 · begonnen am 27. Okt 2015 · letzter Beitrag vom 28. Okt 2015
 
Der schöne Günther

Registriert seit: 6. Mär 2013
6.213 Beiträge
 
Delphi 10 Seattle Enterprise
 
#4

AW: Broken TBytes

  Alt 28. Okt 2015, 08:06
Just use the debugger to inspect your b: TBytes after you've done your b := Stream.Bytes; .

It already contains more bytes than your original file. Since the Bytes property just reads out an ordinary field, something must have gone wrong in LoadFromFile .

The root cause is the protected method Realloc of TMemoryStream , the parent of your TBytesStream . It makes sure the internal byte array is always aligned to a multiple of 8KB.

This way, the Byte property is garbage, you will have to truncate it afterwards, just as Klaus already said:

Delphi-Quellcode:
procedure WhyIsItNotWorking();
const
   path = 'x:\cake.pdf';
var
   Stream : TBytesStream;
   b : TBytes ;
begin
   Stream := TBytesStream.Create();
   Stream.LoadFromFile(path);

   b := Stream.Bytes;
   SetLength(b, Stream.Size); // This is new

   Stream := TBytesStream.Create(b);
   Stream.SaveToFile( path.Replace('cake', 'cake2') );

   FreeAndNil(Stream); // You know that you did not destroy the first TStream instance?
end;

I would have made the same mistake. I don't think this was to be expected.
  Mit Zitat antworten Zitat
 


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 15:08 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