I have manage to make mergefields not editable and non erasable. The user can modify the document but not the merge fields.
Now, I need a way to allow the user to click on a merge field (anywhere on the field) and display a popup. Right now, I get this behaviour only if the user clicks at the beginning of the merge field...
Is there a way to detect the mouse is on top of a merge field? I have tried a number of things w/o any luck.
I am thinking something along this lines (this code does not work)
Code
procedure TEForm.wptDocumentMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
ATextObj : TWPTextObj;
RtfPageNr,
YTwip,
XTwip : integer;
begin
// mouse down
XTwip := TWPRTFEnginePaint(wptDocument).ScreentoTwip(X);
YTwip := TWPRTFEnginePaint(wptDocument).ScreentoTwip(Y);
RtfPageNr := TWPRTFEnginePaint(wptDocument).GetPageAtXY(X,Y);
ATextObj := wptDocument.TextObjects.TextObjectAtXY(RtfPageNr, X, Y);
{
ATextObj := wptDocument.TextCursor.ObjAtCP;
}
if Assigned(ATextObj) AND (ATextObj.ObjType = wpobjMergeField) then
begin
showmessage('object found');
end;
end;
Alles anzeigen