TDBrichedit displays plain text rather than rich text - delphi

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.

Related

FDMemTable Loses FieldDefs information when there is AutoInc Field in Delphi

I am creating a memory table TFDMemTable for a delphi form, and define the fields under FieldDefs. After I am done with the definition of the fields manually, I go to the Fields Editor to add the fields that I just defined.
Everything works perfect until I have an AutoInc type field in my FDMemTable. I am using Delphi 10.3.2 version and I was wondering if I am missing anything or this is a IDE bug.
PS: I have done couple of tests, and I think that if the AutoInc field is not defined as the last field, everything disappears. I am not %100 sure of this case, but pretty much every time I try I loose the fields under FieldDefs.
Here is the steps:
Place a FDMemTable icon
Open FieldDefs window
Create a bunch of fields (string, integer ...)
define the names, types (and sizes for strings)
Open FieldsEditor
Add fields
until here everything works as they should.
Go back to fieldDefs window
create and name a new field with autoinc type
open the fields editor screen and add the last added field.
everything is still good to go as long as there is no more changes in the structure.
Here the weird thing happens if you do the following.
open FieldDefs window
create any field ( lets say integer type )
Go to Fields Editor window to add this last created field.
and you will see that you don't see this new field to add.
when you go back to fieldDefs window to see why it is not showing,
you will see all the previous and last added fields' definitions gone..
In order for me to go around this problem, I open the form in text form and insert the new field right before the last field which is autoinc,
add field editor entry manually in the text form,
and when everything is right, I toggle to form view.

PasswordChar in Delphi XE8's TMemo

I spent a few hours searching Google to see if anyone had shared their articles, but came up empty-handed.
If it's possible, I want to know how to enable/disable the PasswordChar in Delphi XE8's TMemo to hide user input like in TEdit. ? Maybe via a checkbox!
So when the checkbox is checked then all text turned to asterisks, and if the checkbox is unchecked, all text back to normal..
The VCL memo control is a loose wrapper around the Win32 multiline edit. The password character functionality of the edit control is only available for single line edits.
The behaviour is controlled by the ES_PASSWORD style for which the documentation says:
Displays an asterisk (*) for each character typed into the edit control. This style is valid only for single-line edit controls.
The FMX memo control offers no password character functionality for the multiline memo control.
Presumably these frameworks don't offer what you want because passwords are entered in single line edit controls. Developers tend not to provide functionality that has no clear case for being used.
Your options:
Use a single line TEdit.
Write your own multiline memo that supports your desired functionality.
Find a third party multiline memo that supports your desired functionality.
Now, since your question is so general I have assumed that you want full support for single line password character. That is, the user enters text and it appears masked.
But maybe you actually don't need editability. In that case it is simple enough. Do the following:
Load or add the true text into a separate TStringList.
When you want to display the true text assign the string list to the memo.
When you want to hide the content, process the true text into whatever you want to display, and display that.
Make the memo control read only.
if cBoxPassword.checked=false then
edtpassword.PasswordChar:='*';
if cBoxPassword.checked=true then
edtPassword.PasswordChar:=#0;

GroupFooter from FastReports not getting data using DBX instead of ADO in delphi

Since I don't want to use ODBC connections anymore, I'm trying to get DBX work for my reports. Almost everything works the same as it worked with the tfrxAdoQuery, but not the GroupFooter.
I used to have a MasterData that used a ADOQuery1: TfrxAdoQuery and I changed to a DBXQuery1:TfrxDBXQuery. Its fields like [BDXQuery."name"] work fine now than I'm using a different type of query, but only inside the MasterData. This is the way it looks in the MasterData and when the report is displayed it comes correctly:
For some reason, the Footer's tfrxMemoViews dont show the DBXQuery1."anyField" that I try to display.
This is the way it looks in the footer but in the report just dont show the name.
The difference is the DatasetName can't be set for the DBXQuery (as it was set when using the ADOquery). When I was using ADO, the DatabaseName seem to be assinged arbitrarilly with a name like 'header' which did not belong to any component or variable. Now it should be more manageable since the fields that are set are DataSet (wich can be chosen from a group that has all the DataSets, in my case I can choose DBXQuery1) and DataField, which can be chosen from one of the predetermined fields that are in the DBXQuery1.
Any help will be highly appreciated

Getting unformatted text from RichEdit

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

Intraweb question about improperly working (radiobutton)?

HI,
I created 4 radiobuttons in a intraweb application.
One is checked by default, the rest is not.
The belong to the same group called group. (I set the group properly of each TIWradiobutton)
There is twiimage image which has click event. In that click event, I tried to set the radiobuttons.
E.g.
radiobutton1.checked:=true;
The problem is that this sometimes set the radiobutton and sometimes it does not.
I found a fix by setting the rest of radiobuttons.checked to false. That fixed the problem.
I wonder what I did wrong in the first place when I just used one assignment.
Can you tell me if it is a bug in intraweb or I used radiobutton improperly?
Thanks.
just create a IWRadioGroup1(in iwstanderd pallet ) in your form
select IWRadioGroup1 , in the properties panenel dblclick on items
you will get a stringlist editor ,type the captions of your four radiobuttons line by line then click OK
now select your IWImage1 ,goto click events just type th above code
procedure TformMain.IWImage1Click(Sender: TObject);
begin
IWRadioGroup1.ItemIndex := 2 // 2 is the radiobutton number as you typed in stringlist editor
end;
sometimes IW or components build over the IW (e.g TMS suite for IW) have a strange behavior.you can find how it works by looking out in the code, how they manage the java script behind your radio groups.
Also sometimes you must manage the components exactly how Atozed say in their documentation.
Probably isn't the best answer, but if you'll work a lot with IW you'll see that it has a lots of limitations and strange behavior (only if you don't work in their style, which sometimes differs a lot from win32 style).
best regards,

Resources