I have included to the end customer the possibility to insert data fields stored in a TListBox control (lstGlobalVars), using the InsertStringTag function. Each entry in lstGlobalsVars is actually a key to a TDictionary class which stores the values related to the key indexes.
If the user double click the listbox control, the following function is called:
Code: Select all
const
TEXT_BOLD = 1;
TEXT_ITALIC = 2;
TEXT_UNDERLINE = 3;
TEXT_APPLYFONTNAME = 4;
TEXT_APPLYFONT = 5;
TEXT_APPLYFONTSIZE = 6;
TEXT_COLOR = 7;
TEXT_BACKCOLOR = 8;
TEXT_FIELDPROTECT = 9;
procedure TfLstGlobalVars.lstGlobalVarsDblClick(Sender: TObject);
var
idx: integer;
begin
idx := lstGlobalVars.ItemIndex;
with fMain do
begin
SRichViewEdit1.RichViewEdit.ApplyStyleConversion(TEXT_FIELDPROTECT);
SRichViewEdit1.RichViewEdit.InsertStringTag(
DictVars.Items[lstGlobalVars.Items[idx]],
lstGlobalVars.Items[idx]
);
SetFocus;
end;
end;
Code: Select all
procedure TfMain.SRichViewEdit1StyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var
FontInfo: TFontInfo;
begin
FontInfo := TFontInfo.Create(nil);
try
FontInfo.Assign(Sender.Style.TextStyles[StyleNo]);
case UserData of
TEXT_FIELDPROTECT:
begin
FontInfo.Protection := [rvprStyleProtect, rvprModifyProtect, rvprStyleSplitProtect, rvprConcateProtect, rvprRVFInsertProtect, rvprDoNotAutoSwitch];
FontInfo.BackColor := clSilver;
end;
end;
NewStyleNo := Sender.Style.TextStyles.FindSuchStyle(StyleNo, FontInfo,
RVAllFontInfoProperties);
if NewStyleNo=-1 then
begin
Sender.Style.TextStyles.Add;
NewStyleNo := Sender.Style.TextStyles.Count-1;
Sender.Style.TextStyles[NewStyleNo].Assign(FontInfo);
Sender.Style.TextStyles[NewStyleNo].Standard := False;
end;
finally
FontInfo.Free;
end;
end;
This alternative background color is good on screen, but I would like to change it back to clNone (or clWindow) when the document is printed. I have no clue about how to do it. Is it possible?