Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving RichEdit to Access Database 2

Status
Not open for further replies.

browneye

Programmer
Nov 21, 2000
82
US
Hi,
I am using Delphi 2005,Richedit control..trying to save richedit control contents to access database and read from access database using ADO.
I have two questions..
Right now I am using Access 2003 and I am using field type as Memo to save richedit control contents. Can it store pictures too? Or I need to use Ole Object as field type?
I found this code on internet..giving me error Incompatible types 'TBlobfield' and 'Tstream'. Right now its just text I am trying to save.

procedure TForm1.UpdateBlob(IDValue:Integer);
var
blobF : TBlobField;
bs : TStream;
Local_dsLocal :TADODataSet;

begin
Local_dsLocal := GetADODataSet('Select * from TrDetail where id = ' +IntToStr(IDValue));
//blobF := Local_dsLocal.CreateBlobStream(Local_dsLocal.FieldByName('Contents'), bmWrite);
Local_dsLocal.Edit;
bs:=Local_dsLocal.CreateBlobStream(Local_dsLocal.FieldByName('Contents'),bmReadWrite);
rtbox.Lines.SaveToStream(bs);
Local_dsLocal.Post;
end;

What am I doing wrong? Any Idea?

Thank you for your help
 
The compiler error that you get (on the line which you have commented out) is occurring because the CreateBlobStream function returns a TStream, but blobF is declared as a TBlobField.
As far as I know the memo field type in Access is used for holding text. A RichEdit holds formatting information (e.g. text colour) as well as the text itself, so you will not be able to store it in a memo field, you will need to store it in a blob field. A blob field will also be able to hold pictures (a memo field will not)

Steve
 
Steve,
Thank you..I was thinking same. But I was not sure how picture is stored in Richedit
 
You can't not store a picture in a Borland TRichEdit (at least till D6, and I believe they have not changed the class at all), you need another RichEdit class, able to handle OLE.

A couple was laying around in the net, but other than the one coming with RxLib they are difficult to get. Google for RxLib and/or TOleRichEdit. TRichEdit98 rings some bells to, but not sure.

buho (A).
 
buho said:
You can't not store a picture in a Borland TRichEdit...
I'm not trying to be picky but to clear up any confusion, I don't think buho intended the double negative. As far as I am aware, you cannot store a picture in a Borland TRichEdit.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
You are rigth, Stretch :).

Thanks.

buho (A).
 
Well..Issue is not TRichEdit. Im using JVTRichEdit and it supports pictures. Issue is saving part to access db. I tried with CreateBlobStream but wont work.

procedure TForm1.UpdateBlob(IDValue:Integer);
bs : TStream;
blobF : TBlobField;
Local_dsLocal :TADODataSet;
sBuff: PAnsiChar;
begin
Local_dsLocal := GetADODataSet('Select * from StickyDetail where id = ' +IntToStr(IDValue));
Local_dsLocal.Edit;
bs := Local_dsLocal.CreateBlobStream(Local_dsLocal.FieldByName('Contents'), bmWrite);
rtbox.Lines.SaveToStream(bs);
Local_dsLocal.Post;
end;


I also tried...

procedure TForm1.UpdateBlob(IDValue:Integer);
var
blob: TadoblobStream;
fs : TFileStream;
Local_dsLocal :TADODataSet;
sBuff: PAnsiChar;
begin
Local_dsLocal := GetADODataSet('Select * from StickyDetail where id = ' +IntToStr(IDValue));
Local_dsLocal.Edit;
fs := Local_dsLocal.CreateBlobStream(Local_dsLocal.FieldByName('Contents'), bmWrite);
fs := TFileStream.Create('c:\Firebird Login.txt', fmOpenRead);
blob.CopyFrom(fs, fs.Size);
Local_dsLocal.Post;
end;

wont work either..dont know what im doing wrong..
 
What "wont work" means? Are you getting a compiler error? A run time error? An ADO error? No error at all but the data is not saved in the db?

buho (A).

 
browneye,

When you say something won't work can you specify if this is a compile time or run time error? Please give the exact error message that is displayed.

In your second example, where does blob get created? I'm not familiar with ADO but I would have thought that you are creating fs twice and not creating blob which would probably give an Access Violation.

Andrew
Hampshire, UK
 
browneye,

Which line throws up the error in the 2nd example?

Can you answer my second question as to where blob is being created?

I suggest you copy the original code accurately and then you will probably find it compiles and works okay.

Andrew
Hampshire, UK
 
Hi Andrew,
I am back..Sorry for late my uncle passed away..I read your post. I know why you are saying that because you find different code than website..Yes it is true after i copied code it didnt work.so i tried various way to make it work. one of those version copy paste here.
Here is my question..what is wrong with first code? I am copy pasting it here one more time...When I run this code I dont get any error but ole field in table is not updated either.

procedure TForm1.UpdateBlob(IDValue:Integer);
bs : TStream;
blobF : TBlobField;
Local_dsLocal :TADODataSet;
sBuff: PAnsiChar;
begin
Local_dsLocal := GetADODataSet('Select * from StickyDetail where id = ' +IntToStr(IDValue));
Local_dsLocal.Edit;
bs := Local_dsLocal.CreateBlobStream(Local_dsLocal.FieldByName('Contents'), bmWrite);
rtbox.Lines.SaveToStream(bs);
Local_dsLocal.Post;
end;

Your help is appriciated..

Thank you..

 
Not quite sure wether or not this applies here but I found
this in my D7 helpfile:

Code:
Apply pending data changes that have not yet been applied or canceled by calling the UpdateBatch  method. Rows that have been changed and are applied have their changes put into the base tables on which the recordset is based. A cached row marked for deletion causes the corresponding base table row to be deleted. A record insertion (exists in the cache but not the base table) is added to the base table. Modified rows cause the columns in the corresponding rows in the base tables to be changed to the new column values in the cache.

Used alone with no parameter, UpdateBatch applies all pending updates. A TAffectRecords value can optionally be passed as the parameter for UpdateBatch. If any value except arAll is passed, only a subset of the pending changes are applied. Passing arAll is the same as passing no parameter at all and causes all pending updates to be applied. The example below applies only the currently active row to be applied:

ADODataSet1.UpdateBatch(arCurrent);

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
1) Are you sure that the first line GetAdoDataSet(...) is recovering the field you want? May be you are writing your blob in another record.

2) Only guessing, but try bmReadWrite in the line bs := ... instead of bmWrite.

buho (A).
 
Yes GetAdoDataSet is just a common function returns ADO Recordset when SQL statment is passed. Ok I will let you know.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top