Autor Beitrag
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Do 24.02.05 19:59 
Hallo,

ich habe ein Probem, bei dem ich nicht weiterkomme. Ich möchte gerne den Inhalt eines Richedits in ein Blobfeld schreiben und wieder auslesen, dabei das ganze aber packen bzw. entpacken. Ich benutze ZLIB. Leider bekomme ich beim Entpacken einen Fehler (Nur einfach "error", ist blöd aber isso..-).

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure CompressStream(inpStream, outStream: TStream);
var
  InpBuf, OutBuf: Pointer;
  InpBytes, OutBytes: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  try
    GetMem(InpBuf, inpStream.Size);
    inpStream.Position := 0;
    InpBytes := inpStream.Read(InpBuf^, inpStream.Size);
    CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);
    outStream.Write(OutBuf^, OutBytes);
  finally
    if InpBuf <> nil then FreeMem(InpBuf);
    if OutBuf <> nil then FreeMem(OutBuf);
  end;
end;


{ Decompress a stream }
procedure DecompressStream(inpStream, outStream: TStream);
var
  InpBuf, OutBuf: Pointer;
  OutBytes, sz: Integer;
begin
  InpBuf := nil;
  OutBuf := nil;
  sz     := inpStream.Size - inpStream.Position;
  if sz > 0 then
    try
      GetMem(InpBuf, sz);
      inpStream.Read(InpBuf^, sz);
      DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);
      outStream.Write(OutBuf^, OutBytes);
    finally
      if InpBuf <> nil then FreeMem(InpBuf);
      if OutBuf <> nil then FreeMem(OutBuf);
    end;
  outStream.Position := 0;
end;


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
procedure TForm1.Table2AfterScroll(DataSet: TDataSet);

var
  ms2: TMemoryStream;
  bs: TStream;
begin

  WPRichtext1.clear;

  bs := Table2.CreateBlobStream(Table2.FieldByName('e_inhalt'),bmRead);
  try
    ms2 := TMemoryStream.Create;
    try
      DecompressStream(bs, ms2);
      WPRichtext1.LoadFromStream(ms2);
    finally
      bs.Free;
    end;
  finally
    ms2.Free;
  end;



end;

procedure TForm1.Table2BeforePost(DataSet: TDataSet);
var
  ms1, ms2: TMemoryStream;
  bs: TStream;
begin
  ms1 := TMemoryStream.Create;
  try
    bs := Table2.CreateBlobStream(Table2.FieldByName('e_inhalt'),bmWrite);
    try
      WPRichtext1.SaveToStream(ms1);
      CompressStream(ms1, bs);
     finally
      ms1.Free;
      bs.Free;
    end;
  finally

  end;

end;


Der Fehler tritt in der Routine Decompressstream auf. Der Debugger sagt: Ungültige Zeigeroperation...

Was mache ich falsch ?

Danke

Thomas

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

Anmerkung:
Ich weiß nicht, was das Problem ist oder war. Ich habe mir mal Cryptopressstream von aidaim angesehen. Das macht scheinbar genau das, was ich will und bietet auch noch Verschlüsselung..