![]() |
AW: Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
Liste der Anhänge anzeigen (Anzahl: 1)
Habs mal an Delphi 2009 leicht angepasst und versuche "abc" zu komprimieren. Leider klappt es nicht.
LZipper.CopyFrom() gibt eine Stream Read Error Exception. Projekt angehängt.
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ZLib, EncdDecd; type TForm1 = class(TForm) InputEdit: TEdit; CompressedEdit: TEdit; DecompressedEdit: TEdit; CompressButton: TButton; DecompressButton: TButton; procedure CompressButtonClick(Sender: TObject); procedure DecompressButtonClick(Sender: TObject); private function CompressString( const AStr: string ): string; function DecompressString( const AStr: string ): string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.CompressButtonClick(Sender: TObject); begin CompressedEdit.Text := CompressString( InputEdit.Text ); end; procedure TForm1.DecompressButtonClick(Sender: TObject); begin DecompressedEdit.Text := DecompressString( CompressedEdit.Text ); end; function TForm1.CompressString( const AStr: string ): string; var LInput : TStringStream; LZipper : TZCompressionStream; LOutput : TBytesStream; LOutputBytes: TBytes; begin LInput := nil; LOutput := nil; try LInput := TStringStream.Create( AStr, TEncoding.UTF8, False ); LOutput := TBytesStream.Create; LZipper := TZCompressionStream.Create( TCompressionLevel.clMax, LOutput ); try LZipper.CopyFrom( LInput, -1 ); finally LZipper.Free; end; LOutputBytes := LOutput.Bytes; SetLength( LOutputBytes, LOutput.Size ); //Result := TNetEncoding.Base64.EncodeBytesToString( LOutputBytes ); Result := EncodeBase64(LOutputBytes, Length(LOutputBytes)); finally LInput.Free; LOutput.Free; end; end; function TForm1.DecompressString( const AStr: string ): string; var LInputBytes: TBytes; LInput : TBytesStream; LZipper : TZDecompressionStream; LOutput : TStringStream; begin LInput := nil; LOutput := nil; try LInputBytes := DecodeBase64( AStr ); LInput := TBytesStream.Create( LInputBytes ); LOutput := TStringStream.Create( '', TEncoding.UTF8, False ); LZipper := TZDecompressionStream.Create( LInput ); try LOutput.CopyFrom( LZipper, -1 ); finally LZipper.Free; end; Result := LOutput.DataString; finally LInput.Free; LOutput.Free; end; end; end. |
AW: Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
Du musst bei
Delphi-Quellcode:
eine
TStream.CopyFrom
Delphi-Quellcode:
für
0
Delphi-Quellcode:
angeben.
Count
Die Doku ist da eindeutig Zitat:
Delphi-Quellcode:
und dort hatte ich geschaut ... und mit XE8 funktioniert es so ;)
function TStream.CopyFrom(const Source: TStream; Count: Int64): Int64;
const MaxBufSize = $F000; var BufSize, N: Integer; Buffer: TBytes; begin if Count <= 0 then begin Source.Position := 0; Count := Source.Size; end; Result := Count; ... Ich habe den Beitrag entsprechend geändert |
AW: Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
Vielen Dank!
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:46 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