The template is saved in a DB record and later on the application retrieves the template and replace the tags with the data.
For the template editing I drop a TDBRichViewEdit in a form, connect it to the DB and use the following code to add tags to the template:
Code: Select all
function TMyClass.GetFieldStyleNo: Integer;
var
fi: TFontInfo;
begin
fi := TFontInfo.Create(nil);
fi.Assign(FRVEditor.Style.TextStyles[FRVEditor.CurTextStyleNo]);//FRVEditor is a TDBRichViewEdit object
fi.Protection := [rvprModifyProtect, rvprConcateProtect, rvprDoNotAutoSwitch];
Result := FRVEditor.Style.TextStyles.FindSuchStyle(0, fi, RVAllFontInfoProperties);
if Result < 0 then
begin
Result := FRVEditor.Style.TextStyles.Count;
FRVEditor.Style.TextStyles.Add;
FRVEditor.Style.TextStyles[Result].Assign(fi);
FRVEditor.Style.TextStyles[Result].Standard := False;
end;
fi.Free;
end;
procedure TMyClass.InsertTag(const TagName, MyTag: string);
begin
FRVEditor.CurTextStyleNo := GetFieldStyleNo;
FRVEditor.InsertStringTag(Tag, Tag);
FRVEditor.SetFocus;
end;
Code: Select all
for i := 0 to FTemplate.ItemCount - 1 do//FTemplate is another TDBRichViewEdit object
begin
case FTemplate.RVData.GetItemStyle(i) of
rvsLabel:
begin
// do something
end;
end;
end;
Where am I doing wrong ?
Many thanks
Alberto