WPCubed Product Support

Behaviour change V5 to V6 (InputMergeField)

Julian

My memory may be wrong but I think the behaviour has changed between V5 and V6. I insert a user selected merge field into a document using

Document.InputMergeField('fld_' + IntToStr(TMenuItem(Sender).Tag), SubFld(TMenuItem(Sender).name, '_', 3) + ': ' + TMenuItem(Sender).Caption);

With the cursor at the end of the merge field if I then press the enter key the cursor moves down a line, but I HAVE to enter a keyboard character before pressing enter again will work.

Obviously I need to do something differently but what?

Think in terms of setting up a template for a form email. Insert the merge field for the contact name, press enter a couple of times and start typing the text for the email. Only now I can't because the cursor won't move down.

#1 ♥ 0
18.5k Views 4 users read 6 min

Julian

A bit more info - its not just newly inserted merge fields. It also applies to existing ones in a document. Position the cursor after the merge field markers and second presses of the enter button are ignored until a normal key is pressed.

#2 ♥ 0
support

Hi,

I never had this effect - it could be an interaction with an event in the project.

For debugging please don't hide the field markers - then it is better visible where the cursor is.

Julian

#4 ♥ 0

Julian

This is where I'm inserting a mailmerge field programmatically, the markers are visible since I'm setting a template up rather than merging data in. I can see where the cursor is (I think) and if I (for example) enter a space then everythings OK but if I just press CR it isn't accepted.

#5 ♥ 0
support

Hi,

I cannot reproduce it.

For denugging please add a SetFocus after Your insertion code. The cursor should be visible then.

Julian

#6 ♥ 0

Julian

We seem to be having a bit of a communication breakdown. I can see the cursor but it just sits there and doesn't move until I type a character in.

Try this

Drop a TWPRichText (Document) on a form, add a button and in its OnClick event put the following

Document.InputMergeField('fld' + IntToStr(47), 'aaaa');

run it. Click the button, click into the document after the merge field and just press CR. The cursor will move down 1 line (ie the line after the merge field) and "stick" until an alphameric key is pressed a couple of times. The first press isn't displayed.

Roy[/code]

#7 ♥ 0

Just in case it has any relevance my environment is:

Vista Home SP1
D2006 fully patched

#8 ♥ 0

Anyone - anything. Can someone at least confirm that its a problem or is it just me?

#9 ♥ 0
rackerson

Roy,

I don't really have much to add that will help but at least you won't be alone here. I am using a different environment (Delphi 6 on Windows XP) but I am performing identical actions to yours. I programmatically add merge fields both by clicks and drag-n-drop.

Following your steps, I click to add my merge field and position my cursor just after the tag marker and press CR. For me, the CR character is accepted correctly. I tested positioning the cursor BEFORE the merge field, AFTER the merge tag, and INSIDE the merge tags and it worked correctly for me each time. Sorry. Perhaps you have an event that is absorbing the CR key?

Regards,

Rich Ackerson

#10 ♥ 0
support

Hi,

I still cannot reproduce it- But there will be an update soon which has an improve "ShowMergeFields" mode and works much better with selecting + Drag&Drop of merge fields.

From my tests I cannot confirm that this issue is (still) there.

Julian

#11 ♥ 0

At least it looks like its something I'm doing, even if I can't find it. I'll just hold my breath until the new release so if you don't want a death on your hands get releasing <g>

#12 ♥ 0

The good news is it no longer has the problem in a simple test app. The bad news is it still has it in mine. It looks as though I have lots of work.

#13 ♥ 0

Julian

After several hours of deleting components and events I've found the problem - ProtectedProperties ppIsMergedText. If this is true you get the behaviour I've been experiencing.

Should it do this?

#14 ♥ 0
support

Hi,

Yes, I see what you mean. You should really display the merge objects for debugging.

You then can see, that if the cursor is INSIDE the field, before the end tag, it is not possible to enter text. The first character You type skips this object and you can type agaian, AFTER the field.

InputMergeField should place the cursor AFTER the field, I tested in V6.03 that it really does.

For Yor templates consider to use the ShowMergeFields mode - it is pretty powerful, the merge fields casn be easily selected and moved.

Julian

#15 ♥ 0

Julian

Good to see you can now duplicate the effect.

If by "For Yor templates consider to use the ShowMergeFields mode" you mean setting ShowMergeFieldNames to true I've just tried that, and I may go with it as an option (means changing all my names but WTF).

However, it makes no difference to what I think is a problem. The cursor IS flashing outside the merge field BUT if the first key you press is CR there is a problem. Anything else (a..z etc, even #9) is fine but a CR screws it.

#16 ♥ 0

Hi Roy.

I experienced the exact same problem you are having after having updated WpTools 5 to WpTools 6.
I managed to track down the problem to the following code inside unit WPRTEPaint.pas

{$IFDEF WP6} 
              if aCursor.active_posinpar = 0 then
              begin
                apar := aCursor.active_paragraph;
                while (apar <> nil) and (apar.prev <> nil) and (apar.CharCount = 0) do apar := apar.prev;
                protmode := IsProtected(apar, apar.CharCount - 1);
              end else
{$ENDIF}

The same code appears on 2 different places inside the method:
**function TWPRTFEnginePaint.InputString(const Text: string;
HandlePaint: Boolean = FALSE; CodePage: Integer = 0): Boolean;**

If you comment this code i believe all your problems will be gone, at least thats what it did for me.

I also do not understand the logic behind it. If you are at the first position in a empty paragraph the paragraph protection will be decided by the protection on a previous paragraph. It doesn't seem like something most people would consider helpfull.

#18 ♥ 0

Thanks for that now to shout

JULIAN WHAT'S THE OFFICIAL LINE

#19 ♥ 0
support

The problem was caused by setting

Inserting := false

in unit WPCtrMemo, TWPCustomRtfEdit.InputCode.
That has been change in the meantime.

Now it reads

function TWPCustomRtfEdit.InputCode(Code: TWPTextObjType; const AName: string = '';
const command: string = ''; Options: TWPInputCodeOptions = []): TWPTextObj;
var closing: TWPTextObj;
spar, epar: TParagraph;
sposinpar, eposinpar: Integer;
bSelText: Boolean;
bOldInserting: Boolean;
begin
bSelText := FALSE; bOldInserting := FALSE;
try
Changing;
StartUndolevel;
Memo.DisableProtection;
bOldInserting := Inserting;
Inserting := true;

That change should be in the latest WPTools 6.

Julian

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