Solved

Use of Word doc

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

16 Experts available now in Live!

Get 1:1 Help Now