Solved

Use of Word doc

Posted on 1997-05-18
2
265 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now