Mega Code Archive

 
Categories / Delphi / ADO Database
 

Save Load Richedit content (RTF) into an access database

Title: Save / Load Richedit content (RTF) into an access database Question: Sometimes it is needed to save/load rich text format data into an access db without losing its format. It could be done easily in Delphi ! Answer: To save: var ms: TMemoryStream; begin ... ms := TMemoryStream.Create; MyRichEdit.Lines.SaveToStream(ms); ms.Seek(0, soFromBeginning) ; MyADOTable.Active := True; MyADOTable.Insert; //"OLEObjectField" should be defined as "OLE Object" type in Acceess TBlobField(MyADOTable.FieldByName('OLEObjectField')).LoadFromStream(ms); ADOTable.Post; ms.Free; ... To Load: var ms: TMemoryStream; begin ... ms := TMemoryStream.Create; //suppose that the current record in MyAdoTable is the record which //its rtf data should be retrieved TBlobField(MyAdoTable.FieldByName('OLEObjectField')).SaveToStream(ms); ms.Seek(0, soFromBeginning) ; MyhRichEdit.Lines.LoadFromStream(ms); ms.Free; ...