Einzelnen Beitrag anzeigen

Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#1

String ressourcenschonend de/komprmieren

  Alt 20. Mai 2005, 17:05
Hallo,
wie kann ich einen String de/komprmieren?

Ich habe schon das hier gefunden, was aber beim dekomprimieren: "Ungültige Zeigeroperation" ausgibt.

Delphi-Quellcode:
uses
  ZLib;

function CompressString(input:string):string;
var
  InpBuf, OutBuf: Pointer;
  OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, Length(input));
    Move(input[1], InpBuf^, Length(input));
    CompressBuf(InpBuf, Length(input), OutBuf, OutBytes);
    SetLength(result,OutBytes);
    Move(OutBuf^, result[1], OutBytes);
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;

function DeCompressString(input:string):string;
var
  InpBuf, OutBuf: Pointer;
  OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, Length(input));
    Move(input[1], InpBuf^, Length(input));
    DeCompressBuf(InpBuf, Length(input),0,OutBuf, OutBytes);
    SetLength(result,OutBytes);
    Move(OutBuf^, result[1], OutBytes); //[edit]: hier kommt der Fehler
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;
Florian
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)
  Mit Zitat antworten Zitat