Mailmerge, tags and TDBRichViewEdit
Posted: Fri May 13, 2016 10:24 pm
I am adding a mailmerge feature in my application and I have applied the idea in the example MailMergeI
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:
When it comes to mailmerge instead I drop a TDBRichView component in a form, connect it with the DB and use the following code:
When I test the application, FTemplate.RVData.GetItemStyle(i) returns 0 all the time
Where am I doing wrong ?
Many thanks
Alberto
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