Solved

Use of Word doc

Posted on 1997-05-18
2
285 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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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