WPCubed Product Support

PopupMenu on right click field

  1. How I can show a PopupMenu on right click field?

I want show a menu where the user will can set some field's properties (Format, Type of EditField, etc...)

This will open a dialog where I will change the value of Field.Command.

When Merge i will use the value of Field.Command and pass it to TWPWordCommands.Create(Field.Command) to get the value of parameters of Field.

  1. Are u see any mistake in my approach?
#1 ♥ 0
5.2k Views 2 users read 3 min
support

Hi,

To edit an object you can use code likle this

procedure TWPRepTest.WPRichText1TextObjectMouseDown(  Sender: TWPCustomRtfEdit; pobj: TWPTextObj; obj: TWPObject;  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var s : string;begin if (pobj.ObjType=wpobjMergeField) and (Button=mbRight) then begin    s := pobj.Name;    If InputQuery('Field Properties', 'Name', s) then        pobj.Name := s; end;end;

The problem is only that here the user has to exactly click in the start marker of the field.

With the following code the user can clck somewhere between the start and end markers of a field.

procedure TWPRepTest.WPRichText1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var pobj: TWPTextObj;
    par: TParagraph;
    posinpar: Integer;
    s : string;
begin
  if Button = mbRight then
  begin
    pobj := WPRichText1.CodeInsideOf(x, y, wpobjMergeField, par, posinpar);
    if pobj <> nil then
    begin
      s := pobj.Name;
      if InputQuery('Field Properties', 'Name', s) then
        pobj.Name := s;
    end;
  end;
end;

Regards,

Julian

#2 ♥ 0

Julian,

  1. Can I to use the Field.Command to put the things that i need (Type, Format, Template, Value, Deafault)?
  2. If I need put a script pascal on mergefield to be executed on merge where u would put?
#3 ♥ 0
support
  1. Can I to use the Field.Command to put the things that I need (Type, Format, Template, Value, Default)? <<

Yes. It would be best if you encode it. For example as HexString.

In RTF quotes " and parentheses { } can cause trouble here.

  1. If I need put a script pascal on mergefield to be executed on merge where u would put?<<

OnMailMergeGetText event

#4 ♥ 0

U didn't undestood my second question. I wish store the script on document itself. What the limite of Command property?

#5 ♥ 0
support

I think I understood - the 'Command' parameter is internally stored in the property 'Source' of the TWPTextObj. I recommend to hexencode that string - so you can use any character combination in this string.

#6 ♥ 0
  1. How I can set the position X and Y of popup menu when i click on mergefield?
  2. How I can get the Text's Baseline of paragrah on mouse position (to show a picklist). The version do not have GetParXYBaselineScreen like EditField demo then I need a function that calculate this.
#7 ♥ 0
support

Hi,

  1. How I can set the position X and Y of popup menu when i click on mergefield? <<

Note the X and Y parameter in MouseDown event. That has to be converted to screen coordinates (wp.ClientToScreen). Use the result in PopupMenu.Popup(x,y)

  1. How I can get the Text's Baseline of paragrah on mouse position (to show a picklist). The version do not have GetParXYBaselineScreen like EditField demo then I need a function that calculate this.<<

GetParXYBaselineScreen was added quite a while. I assume you use an outdated version. Please get the current.

Julian

#8 ♥ 0
This category is archived. No new posts are possible.