WPCubed Product Support

AV after change of Field.EmbeddedText

Hi Julian,

doing this, "sometimes" an AV occured:

procedure SetField_In(slFeld, slWert : String);
  var tp : TWPTextObj;
      FromStart : Boolean;
  begin
    FromStart := TRUE;
    repeat
      tp := WF.WPRTF.FieldLocate(slFeld, '', FromStart, [wplocGlobalSearch,wplocDontMoveCursor]);
      if tp<>nil then
        tp.Embeddedtext := slWert;
      FromStart := FALSE;
    until tp = nil;
  end;

begin

  par := WPRTF.ActiveParagraph;
  nPos := WPRTF.CPPosInPar;
  ...
  SetField(.....)
  SetField(.....)
  SetField(.....)
  SetField(.....)
  ...
  WPRTF.ActiveParagraph := par;
  WPRTF.CPPosInPar := nPos;
end;

Hope this callstack can help

Thanks

Delphi 7 WPTools 5.07.2007 V5.0 Release 24.3a

Patrick

#1 ♥ 0
3.2k Views 2 users read 2 min
support

Hi,

please do not post any AV logs like this. Usually the problem is caused somewhere else and you only see the result. (I took the freedom to update the caption of your post)

  1. The problem appears to be your code, not in WPTools. You cannot expect that the pointer "par" stored before your search and replace to be valid after that process. So setting WPRTF.ActiveParagraph := par will set the cursor into nirvana. Also a ReformatAll is required after changing "EmbeddedText". To (re)store the cursor position use the integer property CPPosition.
  2. You seem to use FieldLocate to update merge fields. That is sub optimal, simply call MergeText(true) and change the data in the event OnMailMergeGetText.

Regards,

Julian

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