Page 1 of 1
Plain text, apply style programmatically
Posted: Wed Jun 08, 2011 2:44 am
by agent86
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.
Is there a solution to this problem?
Posted: Mon Jun 13, 2011 2:30 am
by agent86
See previos post...
I am still waiting for a solution if there is one. If not please let me know.
Posted: Mon Jun 13, 2011 12:43 pm
by Sergey Tkachenko
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):
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;
2) A combobox control takes focus. Add DBRichViewEdit.SetFocus in your code that applies changes made in this combobox.
Thank you...
Posted: Mon Jun 13, 2011 2:59 pm
by agent86
I'll give this a try. Thank you...
I've done something wrong or did not understand...
Posted: Tue Jun 14, 2011 4:07 am
by agent86
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;
Posted: Tue Jun 14, 2011 10:46 am
by Sergey Tkachenko
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?
Sorry. Error in code...
Posted: Tue Jun 14, 2011 3:15 pm
by agent86
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.
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;
Posted: Wed Jun 15, 2011 5:25 pm
by Sergey Tkachenko
If you want to add a plain text, just write
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;
Or, in a real application, pt will contain a real RTF that you need to display as a plain text?
Why is my font size 12 when we are telling it 10?
Posted: Fri Jun 17, 2011 6:00 am
by agent86
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?
Posted: Fri Jun 17, 2011 4:36 pm
by Sergey Tkachenko
In your procedure? In new version of TRichView, font name and size are taken from RTF. Since TRichView 13, if fonts are not specified in RTF, default RTF font is applied.