I must be blind (and never needed it before) but I can't seem to find out how to add an item at the beginning of a formatted TRichView.
My problem is that I was adding the item for the header, then inserting another TRichView's content, then adding an item for the footer. But when I inserted the TRichView, I lost the background information so now I'm loading the TRichView then adding the footer and... I can't find how to add the header above everything else
Thank you for any help.
John.
Add a text item at the beginning of a TRichView
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Yes, there is only one documented method allowing to add content at the specified place in TRichView: InsertRVFFromStream.
Using undocumented methods, you can insert text item at the specified position using this code:
Using to insert at the beginning:
InsertText(RichView1, 0, 'Title', StyleNo, ParaNo);
This code assumes that rv.Style.TextStyles[StyleNo].Unicode = False. If you need code for Unicode text, let me know.
Using undocumented methods, you can insert text item at the specified position using this code:
Code: Select all
use RVItem;
procedure InsertText(rv: TCustomRichView; ItemNo: Integer; const s: String; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
item.Inserting(rv.RVData, s, False);
rv.RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
end;
InsertText(RichView1, 0, 'Title', StyleNo, ParaNo);
This code assumes that rv.Style.TextStyles[StyleNo].Unicode = False. If you need code for Unicode text, let me know.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
uses CRVData, RVUni;
procedure InsertText(rv: TCustomRichView; ItemNo: Integer; s: String; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
if rv.Style.TextStyles[StyleNo].Unicode then begin
s := RVU_AnsiToUnicode(rv.RVData.GetStyleCodePage(StyleNo), s);
item.ItemOptions := item.ItemOptions+[rvioUnicode];
end;
item.Inserting(rv.RVData, s, False);
rv.RVData.Items.InsertObject(ItemNo, s, item);
item.Inserted(rv.RVData, ItemNo);
end;
Code: Select all
procedure InsertTextW(rv: TCustomRichView; ItemNo: Integer; const s: WideString; StyleNo, ParaNo: Integer);
var item: TRVTextItemInfo;
s2: String;
begin
item := RichViewTextItemClass.Create(RVData);
item.StyleNo := StyleNo;
item.ParaNo := ParaNo;
if rv.Style.TextStyles[StyleNo].Unicode then begin
s2 := RVU_GetRawUnicode(s);
item.ItemOptions := item.ItemOptions+[rvioUnicode];
end
else
s2 := RVU_UnicodeToAnsi(rv.RVData.GetStyleCodePage(StyleNo), RVU_GetRawUnicode(s));
item.Inserting(rv.RVData, s2, False);
rv.RVData.Items.InsertObject(ItemNo, s2, item);
item.Inserted(rv.RVData, ItemNo);
end;