Plain text, apply style programmatically
Plain text, apply style programmatically
RichView 13
I read plain text from a database to the DBRichViewEdit. It comes in as Arial font size 10. I would like it to take on the font and font size in the combo boxes. The default is Trebuchet, font size 10.
Also if I select the plain text and click on font name combobox the text selected in the DBRichView loses focus.
I read plain text from a database to the DBRichViewEdit. It comes in as Arial font size 10. I would like it to take on the font and font size in the combo boxes. The default is Trebuchet, font size 10.
Also if I select the plain text and click on font name combobox the text selected in the DBRichView loses focus.
Is there a solution to this problem?
See previos post...
I am still waiting for a solution if there is one. If not please let me know.
I am still waiting for a solution if there is one. If not please let me know.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1) To define the default font, use OnNewDocument event.
In this event, you can use this code (assuming that your DBRichViewEdit is linked to RVStyle1):
2) A combobox control takes focus. Add DBRichViewEdit.SetFocus in your code that applies changes made in this combobox.
In this event, you can use this code (assuming that your DBRichViewEdit is linked to RVStyle1):
Code: Select all
RVStyle1.TextStyles.Clear;
RVStyle1.TextStyles.Add;
RVStyle1.TextStyles[0].FontName := 'Trebuchet';
RVStyle1.TextStyles[0].Size := 10;
RVStyle1.ParaStyles.Clear;
RVStyle1.TParaStyles.Add;
RVStyle1.ListStyles.Clear;
Thank you...
I'll give this a try. Thank you...
I've done something wrong or did not understand...
This is my procedure. Did not work. I just used a single word for the test...
Code: Select all
procedure TReportWriterMainForm.ConvertPlainTextToRTFRVE ;
var s, pt: TRVAnsiString;
Stream: TMemoryStream;
fs : string ; // font size
begin
// dbrichview
rve.clear ;
pt := 'Booga' ;
Stream := TMemoryStream.Create;
Stream.WriteBuffer(PRVAnsiChar(s)^, Length(s));
Stream.Position := 0;
rve.InsertRTFFromStreamEd(Stream);
Stream.Free;
rvs.TextStyles.Clear;
rvs.TextStyles.Add;
rvs.TextStyles[0].FontName := 'Trebuchet MS';
rvs.TextStyles[0].Size := 10;
rvs.ParaStyles.Clear;
rvs.ParaStyles.Add;
rvs.ListStyles.Clear;
end;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Please describe what exactly you want.
I assumed that you stored a plain text in a database, and you want to define a font for this plain text in a linked TDBRichViewEdit.
I do not understand your code. What's the source of data? You write s to the stream, but s is not initialized. What's the source data format? What do you want in results?
I assumed that you stored a plain text in a database, and you want to define a font for this plain text in a linked TDBRichViewEdit.
I do not understand your code. What's the source of data? You write s to the stream, but s is not initialized. What's the source data format? What do you want in results?
Sorry. Error in code...
I figured I goofed sometyhing up and I did!
I had changed the variable to pt instead of s and forgot to change the s to pt. During my test phase I am using a string, pt, instead of reading from a database. The database will store plain text that must be formatted when I write to the dbrichview.
The following code now "works" but the font size comes in as 12 instead of 10. Otherwise it seems to work.
I had changed the variable to pt instead of s and forgot to change the s to pt. During my test phase I am using a string, pt, instead of reading from a database. The database will store plain text that must be formatted when I write to the dbrichview.
The following code now "works" but the font size comes in as 12 instead of 10. Otherwise it seems to work.
Code: Select all
procedure TReportWriterMainForm.ConvertPlainTextToRTFRVE ;
var pt: TRVAnsiString;
Stream: TMemoryStream;
begin
// dbrichview
rve.clear ;
rvs.TextStyles.Clear;
rvs.TextStyles.Add;
rvs.TextStyles[0].FontName := 'Trebuchet MS';
rvs.TextStyles[0].Size := 10;
rvs.ParaStyles.Clear;
rvs.ParaStyles.Add;
rvs.ListStyles.Clear;
// normally the text will come from a database field
pt := 'This is a test!' ;
Stream := TMemoryStream.Create;
Stream.WriteBuffer(PRVAnsiChar(pt)^, Length(pt));
Stream.Position := 0;
rve.InsertRTFFromStreamEd(Stream);
Stream.Free;
end;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
If you want to add a plain text, just write
Or, in a real application, pt will contain a real RTF that you need to display as a plain text?
Code: Select all
rve.clear ;
rvs.TextStyles.Clear;
rvs.TextStyles.Add;
rvs.TextStyles[0].FontName := 'Trebuchet MS';
rvs.TextStyles[0].Size := 10;
rvs.ParaStyles.Clear;
rvs.ParaStyles.Add;
rvs.ListStyles.Clear;
// normally the text will come from a database field
pt := 'This is a test!' ;
rve.AddTextNL(pt, 0, 0, 0);
rve.Format;
Why is my font size 12 when we are telling it 10?
Do you see the reason I'm getting Font Size of 12 in my Font Size Combo Box instead of 10 as is designated in the procedure above?
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: