Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

...I enjoy spending time on it for personal growth (I learn from the questions I don't answer, and I reinforce/stay sharp on the topics I do answer), and to give back to humanity at large...

Geography

Where in the world do Tek-Tips members come from?

Load and save Richedit Text in databaseHelpful Member! 

Helpful Member!  srobiolle (IS/IT--Management)
23 May 12 9:45
Following the thread thread102-1198575: Saving RichEdit to Access Database :

After 2 hours of web research and tests, I finally found a working solution (using Delphi 7.0) for loading and saving richedit text (with attributes) in an access database.
Rules to follow are :
- the Access field must be of type "OLE Object"
- this field must be in the first position in the query variable(because "fields[0]", see later )
- the query must contain the primary key field (unique id the record), at any but the first position
- you must pass an ADO connection

Here are my functions, adapt them as you like smile

Examples :
Field is "Notes" in table "Actions" with primary key "ID", RE is Richedit component, DB.GetConnection is my own ADO connection

SaveRicheditToAccess (DB.GetConnection, RE, 'SELECT Notes, ID FROM Actions WHERE ID='+IntToStr(ID));
LoadRicheditFromAccess (DB.GetConnection, RE, 'SELECT Notes, ID FROM Actions WHERE ID='+inttostr(id));

Function SaveRicheditToAccess (ADOC : TADOConnection ; RE : TRichEdit ; _Select : String) : Boolean;
var
ms: TMemoryStream;
ADO : TADODataset;
begin
ms := TMemoryStream.Create;
Try
Result := FALSE;

// save content to stream
RE.Lines.SaveToStream(ms);
ms.Seek(0, soFromBeginning) ;

ADO := TADODataset.Create (NIL);
ADO.Connection := ADOC;
ADO.CommandTExt := _SELECT;
ADO.Active := True;
ADO.Edit;
// Put stream content in blob field and post it to database
TBlobField(ADO.Fields[0]).LoadFromStream(ms);
ADO.Post;
Result := TRUE;
Finally
FreeAndNil (ms);
FreeAndNil (ADO);
End;
End;

Function LoadRicheditFromAccess (ADOC : TADOConnection ; RE : TRichEdit ; _Select : String) : Boolean; // Select doit renvoyer LE champ à modifier
var
ms: TMemoryStream;
ADO : TADODataset;
begin
ms := TMemoryStream.Create;
Try
Result := FALSE;
ADO := TADODataset.Create (NIL);
ADO.Connection := ADOC;
ADO.CommandTExt := _SELECT;
ADO.Active := True;
// Load rich edit content into stream
TBlobField(ADO.Fields[0]).SaveToStream(ms);
ms.Seek(0, soFromBeginning) ;
// Load rich edit content from stream to component
RE.Lines.LoadFromStream(MS);
Result := TRUE;
Finally
FreeAndNil (ADO);
FreeAndNil (Ms);
End;
End;

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close