?
Solved

Use of Word doc

Posted on 1997-05-18
2
Medium Priority
?
292 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 300 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

764 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