Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi & Word issue

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
In order to maximize my chances for success, I would also like some delphi exposure to this issue. Thanks!

Leslie

thread707-1412204
 
When any kind of inter-program communication is done, how the data types are represented are of paramount importance. Given the VB examples, we must remember that a VB string is much much different than a Delphi string.


A VB string is a pointer to a Unicode array of characters with a preceding 4 byte length string, and having the array of characters conclude with a null terminator.

From what I see, the data type you want to use in Delphi is LPWSTR as would likely be defined in the windows unit.

Hope this helps some to apply the example given in the other thread.
 
Ok, i've looked into the LPWSTR type which would be the Delphi equivalent of the PWideChar, right? So in the DevGuide: Developing COM-based applications in the help file it indicates that this field type is NOT Automation Compatible and this
help file said:
specifies whether the type can be used by an interface that has its Automation or Dispinterface flag checked. These are the types that COM can marshal via the type library automatically.

Does that mean i CANNOT use this field type?

Here's the procedure that I'm using to pass the long string to the MergeData procedure:

Code:
procedure AddNotes(NoteString : string);
var
NotesList : TStringList;
position, j : integer;
Result : PWideChar;
begin
  NotesList := TStringList.Create;
  while length(NoteString) > 0 do
  begin
    position := pos(';', NoteString);
    NotesList.Add(LeftStr(NoteString, position - 1));
    NoteString := copy(NoteString, position + 1, length(NoteString));
  end;
  for j := 0 to NotesList.Count - 1 do
  begin
    Result := Result + NotesList.Strings[j] + Chr(11)
  end;

  MergeData(WordApp, 'bmNotes', Result);

end;

of course this bombs because I can't assign a string to a PWideChar variable type.....

and here's the MergeData:
Code:
procedure MergeData(varWord: variant; strBookMark: string; strData: string);
  begin
  // if the Bookmark is defined in the document then add the string at that
  // location.
    if varWord.ActiveDocument.Bookmarks.Exists(strBookMark) = True then
      varWord.ActiveDocument.FormFields.Item(strBookMark).Result:= strData;
  end;

I can't figure out what I need to change to get the information into the PWideChar variable type and pass that into my merging process.....

 
try WideString, it is equivalent to the COM BSTR...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
in the other thread, this VBA code has been provided as a solution:
Code:
// if the Bookmark is defined in the document then 
// add the string at that location.
  If varWord.ActiveDocument.Bookmarks.Exists(strBookMark) := True Then  <- this line is fine, it's the ones below!
      With varWord.Selection
         .GoTo what:=wdGoToBookmark, Name:= strBookmark
         .Collapse
         .MoveRight wdCharacter, 1
         .TypeText Text:=strData
      End With
  End If
However, I can't quite get the syntax correct in Delphi to see if it will work for me.

Any help on correcting the syntax will be greatly appreciated!

Thanks,
Les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top