The current version of TRichView does not support multiple columns. But if your application needs to create RTF files having sections with multiple columns, it is possible.
You need to insert RTF code directly. The code is \sect\sbknone\colsN, where N is a column count.
There are two methods available:
1) Using text style with rvteoRTFCode option.
2) Using some control and OnSaveComponentToFile event.
The second method is preferred because you can customize how this RTF code looks like in TRichView, but I will show the both methods.
[Example] How to export RTF having multicolumn sections
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
[Example] How to export RTF having multicolumn sections
Last edited by Sergey Tkachenko on Fri Mar 19, 2010 7:28 pm, edited 1 time in total.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Inserting RTF code for column count using a special text style.
The code above uses the function returning the index of "RTF code" text style:
The disadvantage of this method is in displaying RTF code in TRichView (it may confuse users).
Code: Select all
var s: String;
ColCount: Integer;
begin
s := '1';
if not InputQuery('Columns', 'Enter count of columns:', s) then
exit;
ColCount := StrToIntDef(s, 1);
RichViewEdit1.CurTextStyleNo := GetRTFCodeStyleNo(RichViewEdit1.Style);
RichViewEdit1.InsertText('\sect\sbknone\cols'+IntToStr(ColCount));
// text after this position will be saved in RTF as ColCount columns
end;
Code: Select all
function GetRTFCodeStyleNo(RVStyle: TRVStyle): Integer;
var TextStyle: TFontInfo;
begin
TextStyle := TFontInfo.Create(nil);
TextStyle.Options := [rvteoRTFCode];
TextStyle.Protection :=
[rvprStyleProtect, rvprModifyProtect, rvprConcateProtect,
rvprDoNotAutoSwitch];
Result := RVStyle.TextStyles.FindSuchStyle(0, TextStyle,
RVAllFontInfoProperties);
if Result<0 then begin
with RVStyle.TextStyles.Add do begin
Assign(TextStyle);
Standard := False;
end;
Result := RVStyle.TextStyles.Count-1;
end;
TextStyle.Free;
end;
Last edited by Sergey Tkachenko on Thu Sep 11, 2008 8:37 am, edited 1 time in total.
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Inserting RTF code for column count using controls
You can use any control, in this example I am using TStaticText with Caption = column count.
1) Inserting:
2) OnSaveComponentToFile event:
3) TStaticText must be registered (one time, in the initialization section or when the main form is created:
Update:
2018-Apr-9: for compatibility with TRichView 17.3
You can use any control, in this example I am using TStaticText with Caption = column count.
1) Inserting:
Code: Select all
var s: String;
ColCount: Integer;
StaticText: TStaticText;
begin
s := '1';
if not InputQuery('Columns', 'Enter count of columns:', s) then
exit;
ColCount := StrToIntDef(s, 1);
StaticText := TStaticText.Create(nil);
StaticText.Font.Color := clYellow;
StaticText.Color := clBlack;
StaticText.Caption := IntToStr(ColCount);
StaticText.Hint := IntToStr(ColCount)+' column(s)';
RichViewEdit1.InsertControl('', StaticText, rvvaBaseline);
end;
Code: Select all
procedure TForm3.RichViewEdit1SaveComponentToFile(Sender: TCustomRichView;
Path: TRVUnicodeString; SaveMe: TPersistent; SaveFormat: TRVSaveFormat;
var OutStr: TRVUnicodeString);
begin
if (SaveFormat=rvsfRTF) and (SaveMe is TStaticText) then
OutStr := '\sect\sbknone\cols'+TStaticText(SaveMe).Caption;
end;
Code: Select all
RegisterClass(TStaticText);
2018-Apr-9: for compatibility with TRichView 17.3
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: