Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR) (https://www.delphipraxis.net/186310-programm-verhaelt-sich-anders-unter-windows-10-de-und-windows-10-kor.html)

Shark99 23. Aug 2015 10:03

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.

Sir Rufo 23. Aug 2015 10:15

AW: Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
 
Du musst bei
Delphi-Quellcode:
TStream.CopyFrom
eine
Delphi-Quellcode:
0
für
Delphi-Quellcode:
Count
angeben.

Die Doku ist da eindeutig
Zitat:

Wenn Count 0 ist, setzt CopyFrom vor dem Lesen die Position in Source auf 0 und kopiert dann den gesamten Inhalt von Source in den Stream. Ist Count größer bzw. kleiner als 0, liest CopyFrom aus der aktuellen Position in Source lesen.
... aber der Quellcode (in XE8) folgt seinen eigenen Regeln
Delphi-Quellcode:
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;
  ...
und dort hatte ich geschaut ... und mit XE8 funktioniert es so ;)

Ich habe den Beitrag entsprechend geändert

Shark99 23. Aug 2015 10:28

AW: Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
 
Vielen Dank!


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:59 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