Hi Can you help with following error
Hi Can you help with following error
" [dcc32 Error] uCustomer.pas(389): E2010 Incompatible types: 'TBlobStream' and 'TStream' "
What i am Trying to do is Save PDF file to SQL Table , for that i am using Genosite PDFDocument Component
Code i am using as below
procedure TfCustomer.BitBtn1Click(Sender: TObject);
var
selectedFile: string;
dlg: TOpenDialog;
Name:string;
blob: TBlobStream;
TempStrm: TMemoryStream;
begin
selectedFile := '';
dlg := TOpenDialog.Create(nil);
try
dlg.InitialDir := 'C:\';
dlg.Filter := 'PDF (.pdf)|.pdf';
if dlg.Execute(Handle) then
selectedFile := dlg.FileName;
Name:= '';
Name:= OpenDialog1.FileName;
finally
dlg.Free;
end;
if selectedFile <> '' then
QCustomerDocument.Open;
if not (QCustomerDocument.State in [dsEdit, dsInsert]) then
QCustomerDocument.Insert;
// Create a blob stream for writing
blob := QCustomerDocument.CreateBlobStream(QCustomerDocument.FieldByName('PDFDoc'),bmWrite);
try
// Move to the beginning of the blob stream for read operations
blob.Seek(0, soFromBeginning);
// Create a memory stream
TempStrm := TMemoryStream.Create;
// Load a PDF document
gtPDFDocument1.LoadFromFile(Name+'pdf');
// Steps for modifying the PDF omitted.
// Save the PDF document to the stream
gtPDFDocument1.SaveToStream(TempStrm);
// Move to the beginning of the memory stream for read operations
TempStrm.Position := 0;
// Copy the stream to the blob
try
blob.CopyFrom(TempStrm, TempStrm.Size) ;
QCustomerDocument.FieldByName('CustomerID').AsString := Trim(DBCustID.Text);
QCustomerDocument.FieldByName('DocumentName').AsString := Name;
QCustomerDocument.Post;
finally
TempStrm.Free
end;
finally
blob.Free
end;
end;
" [dcc32 Error] uCustomer.pas(389): E2010 Incompatible types: 'TBlobStream' and 'TStream' "
What i am Trying to do is Save PDF file to SQL Table , for that i am using Genosite PDFDocument Component
Code i am using as below
procedure TfCustomer.BitBtn1Click(Sender: TObject);
var
selectedFile: string;
dlg: TOpenDialog;
Name:string;
blob: TBlobStream;
TempStrm: TMemoryStream;
begin
selectedFile := '';
dlg := TOpenDialog.Create(nil);
try
dlg.InitialDir := 'C:\';
dlg.Filter := 'PDF (.pdf)|.pdf';
if dlg.Execute(Handle) then
selectedFile := dlg.FileName;
Name:= '';
Name:= OpenDialog1.FileName;
finally
dlg.Free;
end;
if selectedFile <> '' then
QCustomerDocument.Open;
if not (QCustomerDocument.State in [dsEdit, dsInsert]) then
QCustomerDocument.Insert;
// Create a blob stream for writing
blob := QCustomerDocument.CreateBlobStream(QCustomerDocument.FieldByName('PDFDoc'),bmWrite);
try
// Move to the beginning of the blob stream for read operations
blob.Seek(0, soFromBeginning);
// Create a memory stream
TempStrm := TMemoryStream.Create;
// Load a PDF document
gtPDFDocument1.LoadFromFile(Name+'pdf');
// Steps for modifying the PDF omitted.
// Save the PDF document to the stream
gtPDFDocument1.SaveToStream(TempStrm);
// Move to the beginning of the memory stream for read operations
TempStrm.Position := 0;
// Copy the stream to the blob
try
blob.CopyFrom(TempStrm, TempStrm.Size) ;
QCustomerDocument.FieldByName('CustomerID').AsString := Trim(DBCustID.Text);
QCustomerDocument.FieldByName('DocumentName').AsString := Name;
QCustomerDocument.Post;
finally
TempStrm.Free
end;
finally
blob.Free
end;
end;
As Chris Rolliston pointed out, every data access component technology has its own TStream descendent for the stream they return in CreateBlobStream. So your variable needs to be of type TStream. That's what the error message says. You can easily see the return type with the help of code-completion. Your variable needs to be of that type.
ReplyDeleteFor copying contents to the field, you can also write directly to the field like so:
....
var
LBuffer: TBytes;
begin
// Dataset must be in Edit state.
SetLength(LBuffer, TempStream.Size);
TempStream.Position := 0;
TempStream.Read(LBuffer, Length(LBuffer));
...FieldByName('PDFDoc').AsBytes := Copy(LBuffer, 0, Length(LBuffer));
...
...Post
Hi Girish
ReplyDeletethanks for your support, i need one more support from you, can you tell me
how can view PDF file from SQL Table,
i am able to save PDF file to table with following code
Query.Open;
if not ( Query .State in [dsEdit, dsInsert]) then
OpenDialog1.Filter:='*.pdf|*.pdf';
if OpenDialog1.Execute then
begin
* Query *.Insert;
TBlobField( Query .FieldByName('PDFDoc')).
LoadFromFile(OpenDialog1.FileName);
Query .Post;
end;
now i need to load this file and show in side delphi , using TAcro PDF
or gtDBDocumentViewer1 , can you help me how to do coding. thanks and
waiting
Regards
The gtDBDocumentViewer is exactly for that. To load and show documents stored in blob fields and to save loaded documents back to the blob field. Just hook up the DataSource and DataField properties of the gtDBDocumentViewer to your data-source and blob field. That will do the job.
ReplyDelete