Board index » delphi » Streaming RTF Control Contents to Database BLOB Fields

Streaming RTF Control Contents to Database BLOB Fields

Hi there,

I'm having trouble moving a stream from an RTF or Memo field to a database
BLOB field.  I appreciate if anyone out there have done that before can send
me a sample code or some direction.  Below is the code I'm trying, using the
little information on the online documentation (not even one example).  Of
course I'm getting the Incompatible data types BLOB and TStream.

implementation
{$R *.DFM}

procedure TForm1.bInsertClick(Sender: TObject);
var MyStream: TStream;
begin
      with q1 do
      begin
          if Active then Close;
          SQL.Clear;
          SQL.Add('INSERT INTO BLOBS VALUES (2, "This is a test",
:BLOBPARM');
          MyStream.WriteComponent(RTF1);
          ParamByName('BLOBPARM').AsBlob := MyStream;
          ExecSQL;
     end;
end;

 

Re:Streaming RTF Control Contents to Database BLOB Fields


Look up TParam.LoadFromStream.  If you use a live query, you should also
look at TBlobField.LoadFromStream and SaveToStream.

V/R
Russell L. Smith

Quote
Hassan Yousry wrote in message <74cjfh$4...@forums.borland.com>...
>I'm having trouble moving a stream from an RTF or Memo field to a database
>BLOB field.  I appreciate if anyone out there have done that before can

send

Re:Streaming RTF Control Contents to Database BLOB Fields


Hi Russell,

I took a look at all references to TBlob in the online documentation.
Unfortunately the only example there copies a Blob Field from table "A" to
another Blob Field in table "B".  Very useless example as you can see..the
problem is getting there and out to a different data type (e.g. Memo, RTF
etc.).  Anyway I tried different ways using the supplied procedures an
properties usin the code sample below and in all cases I keep getting the
runtime error "Variance doesn't reference an automation object."  Now that
sounds an OLE operation type error, I'm really getting confused.  Please let
me know if you can see the proble with the code sample below or if you have
any suggestions.

procedure TForm1.bEditClick(Sender: TObject);
begin
  with q1 do
  begin
    try
    q1.Edit;
    q1['BLOBDESC'] := E2.Text;
    //q1['BLOBBODY'].LoadFromFile('F:\A\Summary.Doc');
    //q1['BLOBBODY'].AsString := 'This is my test string';
    q1['BLOBBODY'].value := 'Yet another test string';
    Post;
    Finally
    Close;
    end;
  end;
end;

Thanks in advance;
Hassan

Quote
Russell L. Smith wrote in message <74ct01$4e...@forums.borland.com>...
>Look up TParam.LoadFromStream.  If you use a live query, you should also
>look at TBlobField.LoadFromStream and SaveToStream.

>V/R
>Russell L. Smith

>Hassan Yousry wrote in message <74cjfh$4...@forums.borland.com>...
>>I'm having trouble moving a stream from an RTF or Memo field to a database
>>BLOB field.  I appreciate if anyone out there have done that before can
>send

Re:Streaming RTF Control Contents to Database BLOB Fields


One more thing I should have mentioned that I'm using Delphi 4.2 against
Oracle 8.0.4.
Quote
Russell L. Smith wrote in message <74ct01$4e...@forums.borland.com>...
>Look up TParam.LoadFromStream.  If you use a live query, you should also
>look at TBlobField.LoadFromStream and SaveToStream.

>V/R
>Russell L. Smith

>Hassan Yousry wrote in message <74cjfh$4...@forums.borland.com>...
>>I'm having trouble moving a stream from an RTF or Memo field to a database
>>BLOB field.  I appreciate if anyone out there have done that before can
>send

Re:Streaming RTF Control Contents to Database BLOB Fields


q1['BLOBDESC'] uses the default property of TQuery, which is FieldValues.
FieldValues is an indexed property of type Variant.  The LoadFromFile method
is a TField method, so you must get a reference to the TField.  Try
something like this:

create table temp (
  key_id number not null primary key,
  file_bl long raw
)

    with TQuery.Create(nil) do
    try
      DatabaseName := 'nadd';
      SQL.Text := 'select KEY_ID, FILE_BL from TEMP where KEY_ID = :KEY_ID';
      RequestLive := True;
      ParamByName('KEY_ID').Value := 1;
      Open;
      Edit;
      (FieldByName('FILE_BL') as
TBlobField).LoadFromFile('C:\Autoexec.bat');
      Post;
      Close;
    finally
      Free;
    end;

The cast is unnecessary if you use persistent TFields and a specific field
reference.  Also note I tested with a LONG RAW.  In Oracle8, you would be
better off using a BLOB.

V/R
Russell L. Smith

Quote
Hassan Yousry wrote in message <74h9sp$7r...@forums.borland.com>...
>  with q1 do
>  begin
>    try
>    q1.Edit;
>    q1['BLOBDESC'] := E2.Text;
>    //q1['BLOBBODY'].LoadFromFile('F:\A\Summary.Doc');
>    //q1['BLOBBODY'].AsString := 'This is my test string';
>    q1['BLOBBODY'].value := 'Yet another test string';
>    Post;
>    Finally
>    Close;
>    end;
>  end;

Re:Streaming RTF Control Contents to Database BLOB Fields


Hi,

This worked for me:

  table1.fieldbyname('FIELD1').assign(richedit1.lines)

However there are a DBRichEdit that can be used for this.
I d recommend you to use those whenever possible.

Regards, Fredrik Larsson.

Re:Streaming RTF Control Contents to Database BLOB Fields


You create a TBlobStream object on the desired field, then use
TMemo.Lines.SaveToStream(theStream);
The TBlobStream constructor requires a TBlobField as a parameter. A complete
example should be:

var
    theStream: TBlobStream;
begin
    theStream := TBlobStream.Create(MyTable.FieldByName('MyBlobField'),
bmWrite);
    Memo1.Lines.SaveToStream(theStream);

Russell L. Smith escreveu na mensagem <74ct01$4e...@forums.borland.com>...

Quote
>Look up TParam.LoadFromStream.  If you use a live query, you should also
>look at TBlobField.LoadFromStream and SaveToStream.

>V/R
>Russell L. Smith

>Hassan Yousry wrote in message <74cjfh$4...@forums.borland.com>...
>>I'm having trouble moving a stream from an RTF or Memo field to a database
>>BLOB field.  I appreciate if anyone out there have done that before can
>send

Other Threads