Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi TStringStream to BlobStream (https://www.delphipraxis.net/83979-tstringstream-blobstream.html)

mr_fahrrad 9. Jan 2007 18:02

Datenbank: SqlExpress • Zugriff über: aDO

TStringStream to BlobStream
 
Hi

I have a problem when I try use the copyFrom to copy a BlobStream from a StringStream



Delphi-Quellcode:
procedure TfrmHelpEdt.sButton2Click(Sender: TObject);
var
blob:TStream;
StringStream : TStream;
begin

  with ADOTbl_HTDATA do //is a AdoTable
    begin
      Active:=true;
      Insert;
       blob:=CreateBlobStream(FieldByName('HD_source'), bmWrite);
       StringStream:=TStringStream.Create(getHtml); //getHTML function Return a string
       blob.Position:=0;
       blob.Seek(0, soFromBeginning);
       blob.CopyFrom(StringStream, StringStream.size);
      Post;
      Active:=false;
    end;
The field HD_Source not allow null and the error say "cannot insert null value in hd_source"...
so, I belive that error is in the line blob.CopyFrom(StringStream, StringStream.size);

Can anyone help me?

Der_Unwissende 9. Jan 2007 19:14

Re: TStringStream to BlobStream
 
Hi,
these lines look a little redundant

Zitat:

Zitat von mr_fahrrad
Delphi-Quellcode:
  blob.Position:=0;
  blob.Seek(0, soFromBeginning);

The both of them should do the same, but

Zitat:

Zitat von mr_fahrrad
Delphi-Quellcode:
  blob.Position:=0;
  StringStream.Position := 0;

should do better (untested, I might be wrong)

Regards, Der Unwissende

[ADD]
If HD_source is non-nullable, you probably should ensure that getHTML returns a valid string (<> '')
[/ADD]

Muetze1 9. Jan 2007 19:24

Re: TStringStream to BlobStream
 
The 2nd parameter of CopyFrom() (the size) can be zero, if you want to copy the whole passed stream. In this case, the source stream will also be seeked to position 0 before copy. Otherwise (if you pass any size value > 0), you have to ensure that the read position is as expected on zero position before calling CopyFrom()


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