Using Delphi 11.1 and MySQL ver 8
When reading formatted text stored in a MySQL BLOB feild with TADOQuery and show it in a DBRichEdit the text shows but not the embedded images.
The text with images is saved to the database from a RichEdit via TStringStream to a blob field in the database.
If I use same data but a TStringStream
"MyText := TStringStream.Create(ADOQuery.FieldByName('MyBlobField').AsString);"
and load it to a TRichEdit with
"RichEdit1.Lines.LoadFromStream(MyText)"
the images are showing as they should.
Why is it not working when using TDBRichEdit directly connected to the field with a DataSource?
Regards
Dag
Related
The context is that I am maintaining an application running on delphi 7 with the BDE. I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents. When the relevant forms open, the unformatted text is displayed and then once say the person moves onto the next document, suddenly the rich text kicks in; I suspect it must be an initialisation problem of sorts, but what am I missing; could not locate a solution online.
Thanks
Ordinarily, I would not post an answer to a q which states
I programmatically assign dbricheditcontrols' datafields to allow users to edit rtf documents
but fails to include the code that you are using - you should have provided an MCVE (see https://stackoverflow.com/help/mcve).
However, what you say sugggests that you may be going about what you are trying to do the wrong way. You say you are using a TDBRichEdit component, but if you are using it correctly, it should not require any programmatic assignment of datafields to do it: you simply need to connect the component to the TTable or TQuery you are using via a TDataSource component, and configure the DBRichEdit to access whatever field of the TTable/TQuery that stores the richedit text. That can be done a design time using the Object Inspector in the IDE to set properties and does not require any code.
So, it seems to me that either you are not using the DBRichEdit correctly, or you are trying to do something that you have not explained in your q.
You can satisfy yourself that a DBRichEdit works automatically, without needing to load or save its contents in code, as follows:
Open the FishFacts demo
Add a TDBNavigator and a TDBRichEdit to the form. Set the DataField property of DBRichEdit1 to Notes.
Set the ReadOnly property of Table1 to False. Then set Table1's Active property to True.
Compile and run the project. While it's running
Start WordPad.Exe and create a bit of richtext in it. Copy it to the clipboard. Click the Save speedbutton of DBNavigator1.
Paste the richtext into DBRichEdit1.
You should find that you can navigate away from and back to the edited record and the richtext will be automatically reloaded.
Also, the following code works fine for me to load the Notes field from an .Rtf file
procedure TForm1.Button1Click(Sender: TObject);
begin
Table1.Edit;
TMemoField(Table1.FieldByName('Notes')).LoadFromFile('D:\test.rtf');
end;
and does not initially display the unformatted text as you describe. So I'm fairly sure you problem is arising in code of yours that you haven't shown us.
Btw, the only reason I am posting this as an "answer" is that there is more to say than will comfortably fit in a comment.
Using an Interbase database I have an application in which I want to show the contents of an memo field.
I have created a datamodule on which I put a TIBDatabase, TIBTransaction, TDataSource and TIBTable all connected. Data comes out, no problems so far.
But when I add a TDBMemo to a form and want to show the contents all I get is this;
I have only set the DataSource and DataField on the TDBMemo so there is no further code involved.
Any thoughts?
Solved it by replacing the TDBMemo with an TMemo and adding the contents to it with;
Encoding.Unicode.GetString(myQuery.FieldByName('myField').AsBytes);
We are trying to make our app unicode compatible and we are migrating from delphi 2007 to delphi xe2, we came across few issues and need suggestions regarding them
1) one change is to store blob data having unicode strings in database
We store huge xml data as blob in database, but in latest delphi version(xe2), blob is treated as an array of bytes. So what should be done to store blob data in database, have tried like converting Param.AsBlob := WideBytesOf(xml) but that doesn't seem to work.
2) Also we use HyperString from EFD systems for faster string manipulations, but now the unicode version of this library is not available, have compiled the code by changing the ansistring to string and tried to modify few assembly language instructions but was succesful with only few till now, so can any one suggest any alternative for faster string manipulations
I was searching the internet about half a year how to properly put a Blob in a Database and i found one sollution that worked for me perfectly maybe it will help you also:
Image - TcxImage component
MainQuery - TQuery component
MainQueryPicture - its a Blob field in from the database stored in the Query component through the Field Editor
ImagePath - String variable which hold the path to the image file
MainQuery.Edit;
if Image.Picture.Graphic <> nil then //if there is an image loaded to the component
begin
MainQueryPicture.LoadFromFile(ImagePath); //load the image to a blob field
end;
MainQuery.Post; //post any changes to the table
Hope it helps.
I have a Richedit that allows my users to format and view error messages that display within my application.
I now need to be able to export the text only (no formatting) out to another database that their trouble-ticket system uses.
I have tried all the combinations of PlainText I can think of and I always still get the rtf formatting.
How can I get the text only?
To obtain the unformatted text, simply use RichEdit1.Text.
Answering the direct question that you asked, the Text property is precisely what you are looking for. For some reason it doesn't show up in the TRichEdit documentation, but it is inherited from TCustomEdit.
It sounds to me (following comments to Andreas' answer) as though what you really need to do it as follows:
Pull the RTF from the DB into a memory stream or perhaps a blob stream.
Call RichEdit.LoadFromStream passing that stream, making sure PlainText is False.
Then read RichEdit.Text to get the unformatted text.
At the moment you are simply putting the RTF into the control as plain text. You need to put it into the control as rich text, and for that you need LoadFromStream.
i use this way to get unformatted text
procedure TMainForm.O1Click(Sender: TObject);
begin
if sOpenDialog1.Execute then
sRichEdit1.Lines.LoadFromFile(sOpenDialog1.FileName);
sMemo1.Text := sRichEdit1.Text;
sRichEdit1.Clear;
sRichEdit1.Text := sMemo1.Text;
for save file you have to choices
save as .txt the text still in memo but all change you made will be in richedit only so you have to move text to memo after done all your changes then save it from memo
save as .rtf just save it from richedit
I hope thats help you
We have faced a very strange problem. We are running a firebird 2.5 database with the following table structure.
CREATE TABLE TEST (
ID INTEGER NOT NULL,
MEMO BLOB SUB_TYPE 1 SEGMENT SIZE 80,
DATO TIMESTAMP
);
ALTER TABLE TEST ADD CONSTRAINT PK_TEST PRIMARY KEY (ID);
We are using Firebird 2.5.1 + ODBC 2.0.0.151 on Windows 7.
We use Delphi XE, with TADOConnection + TADODataSet + TDataSetProvider + TClientDataSet to connect to the database.
The problem is when we insert (or update) a new record into the ClientDataSet and updating the field MEMO. (TMemoField) (This has been working perfekt in FB 1.5 and with all versions of MS SQL server).
Now with a firebird 2.5 database we get the error message "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." when running from the Delphi IDE, but no error if we run outside.
The big problem is that the time part of the field DATO is gone when we update the field MEMO. If we don't include the MEMO field, everything is OK.
One other strange thing is that if we use the TADODataSet directly to update the fields, everything works fine. It's only when updated through the ClientDataSet it is a problem.
I have made a small demo project illustrating the problem.
Test.zip (1090 KB):
http://www.consultas.no/u/3037f738
All tips and hints will be highly appreciated!
Best regards,
Bjørn Larsen
Have you tried using TBlobField instead of TMemoField for the blob ?
Sorry, I don't have Delphi available right now to play around locally.