Solved

Use of Word doc

Posted on 1997-05-18
2
289 Views
Last Modified: 2010-04-04
How can I get access to  a Word document, fill in some variable fields (mail merge like)  and print the document out of Delphi 1.0
0
Comment
Question by:softinfo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Expert Comment

by:rkin005
ID: 1336401
You can create ole objects, including word.  Then look at the type library for Word to see what the methods are that you can call.
To create the object you do something like:

uses     OleAuto,           (or ComObj)

myDoc : Variant;

myDoc := CreateOLEObject('Word.Application');

then you do stuff like

myDoc.foo('blah');

depending on the actual method you want.

I can't remember where you find the type library, but you should be able to find it in the registry:
run regedit, search for Word.Application, get the class id and search for that.  One of the occurrences will be refering to the location of a type library, which should contain the information.

Otherwise look in the Word API docs :)


0
 
LVL 1

Accepted Solution

by:
olmy earned 100 total points
ID: 1336402
I had a same problem. You Have two choices DDE or OLE.

OLE: As you know Delphi 1.0 OLE support is very lame. But there is one component that will help you. It is called TAutomationOle (costs about 40 USA Dollars) from "toleauto@swdev.co.nz" (he is the author of the component), but it will only work in win95/NT (not in Windows 3.x). With it you can use macro commands and functions.

DDE: Will do almost everything. Except you cannot execute functions. It is a problem because you cant ask any questions from word (example - is the datasource already installed). BUT IT WILL DO.

You will need following codes (These are cuts from my codes. Mail and ask if there is something that you dont understand):

(* Is word already loaded *)
function TMergeDoc.GetProgramHandle : Hwnd;
var
  buffer : ARRAY[ 0..79 ] of char;
begin
  strpcopy( buffer,  'OpusApp');
  result := FindWindow( buffer, nil);
end;(* getProgramHandle *)

(* Is word already loaded *)
function TMergeDoc.ServerRunning : boolean;
begin
  result := GetProgramHandle <> 0;
end;(* getProgramHandle *)

(* start word *)
function TMergeDoc.StartServer : boolean;
var
  buffer : array[ 0..80 ] of char;
  ii : integer;
begin
  screen.cursor := crHourGlass;
  try
    ii := 0;
    (* selvitetään ohjelman hakemistopolku *)
    strPCopy( buffer, 'c:\program\msoffice\word\winword.exe');
    ii := WinExec( buffer, SW_MINIMIZE );

  finally
    result := ii > 22;
    screen.cursor := crDefault;
  end;(* try *)
end;(* getProgramHandle *)

(* open dde link *)
function TMergeDoc.StartLink : boolean;
begin
  Application.processmessages;
  if DdeClient.setlink( 'WinWord','System') then
  begin
    Application.processmessages;
    DdeClient.openlink;
    Application.processmessages;
    result := true;
  end else(* setlink *)
    result := false;
end;(* StartLink *)

(* these are the function that you might need when mailmergeing. You will find them in word on helpfiles

[FileNew]
[FileOpen.Name = "%s"]
[MailMergeMainDocumentType(2)]
[MailMergeOpenDataSource.Name = "%s"]
[MailMergeToPrinter]
[MailMergeToDoc]

*)

(* Oh yes, one usefull routine to determine is there documents already open *)

function TMergeDoc.HasDocument : boolean;
var
  TheData: PChar;
  buffer : string;
  count, ii : integer;
begin
  TheData := DDEClient.RequestData( 'Topics' );
  buffer := strpas( thedata );
  count := 0;
  for ii := 1 to length( buffer ) do
    if buffer[ ii ] = #9 then
      inc(count);

  result := count > 1;
end;(* 1 *)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question