AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)
Thema durchsuchen
Ansicht
Themen-Optionen

Programm verhält sich anders unter Windows 10 (DE) und Windows 10 (KOR)

Ein Thema von Shark99 · begonnen am 22. Aug 2015 · letzter Beitrag vom 23. Aug 2015
Antwort Antwort
Seite 2 von 2     12   
Shark99

Registriert seit: 16. Mai 2007
403 Beiträge
 
#11

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

  Alt 23. Aug 2015, 10:03
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.
Angehängte Dateien
Dateityp: zip CompressBytes.zip (282,0 KB, 3x aufgerufen)
  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
 
#12

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

  Alt 23. Aug 2015, 10:15
Du musst bei TStream.CopyFrom eine 0 für 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
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
Shark99

Registriert seit: 16. Mai 2007
403 Beiträge
 
#13

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

  Alt 23. Aug 2015, 10:28
Vielen Dank!
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


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 00:13 Uhr.
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