<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.6000.16544" name=GENERATOR>
<STYLE>@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; }
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
COLOR: windowtext; FONT-FAMILY: Arial; mso-style-type: personal-compose
}
DIV.Section1 {
page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=fr dir=ltr align=left><FONT face=Tahoma
size=2>-----Message d'origine-----<BR><B>De :</B> Chris Kelling
[mailto:kellingc@cox.net] <BR><B>Envoyé :</B> samedi 7 janvier 2012
16:05<BR><B>À :</B> Lazarus mailing list<BR><B>Objet :</B> [Lazarus]
Intergrating with office suites<BR><BR></FONT></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I’m trying to integrate a couple
of functions that integrate with MS Office (and/or Open Office).
One is using an existing Word template for generating a completed form, and
the other is trying to use Outlook to email reports. Does anyone have a
resource that I can use to figure out how to do
this?<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">-Chris<FONT color=#0000ff><SPAN
class=828293416-07012012> </SPAN></FONT></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT
color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </P></DIV></BLOCKQUOTE>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>The easiest is to use COM with late binding.
Sounds difficult but it isn't. Example to send an email with
attachment:</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>uses ComObj;</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>...</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>procedure TForm1.Button1Click(Sender:
TObject);<BR>const olMailItem=0;</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>var Mail,Message:variant;</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>begin<BR> // attach to running outlook<BR>
Mail:=GetActiveOleObject('Outlook.Application');<BR>
Message:=Mail.CreateItem(olMailItem);<BR> Message.Recipients.Add(<A
href="mailto:'first@recipient'">'first@recipient'</A>);<BR>
Message.Recipients.Add(<A
href="mailto:'second@recipient'">'second@recipient'</A>);<BR>
Message.Subject:= 'This is the subject';<BR> Message.Body:= 'Hi from
lazarus';<BR> Message.CC:='cc@recipient';<BR>
Message.Attachments.Add('C:\lazarus\readme.txt') ;<BR>
Message.Send();<BR>end;<BR></SPAN></FONT></SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>The example assumes outlook is already running. You can
also start up Outlook by doing:</SPAN></FONT></SPAN></P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>Mail:=CreateOleObject('Outlook.Application');</SPAN></FONT></SPAN></P>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>To know what you can do with this com object, google
for 'Outlook.Application' and you'll find hundreds of examples, mainly
using VB or VBA. The methods and properties are however the same. Or use
the reference manual at <A
href="http://msdn.microsoft.com/en-us/library/aa210897%28v=office.11%29.aspx">http://msdn.microsoft.com/en-us/library/aa210897%28v=office.11%29.aspx</A>.
</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>Similar, to "automate" word do
a</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>GetActiveOleObject('Word.Application');</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>Automating openoffice is possible but you'll find far
less help for this. </SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>An alternative is to use early binding. In latest fpc
trunk, you'll find a typelib import utility (importtl) that creates the bindings
for com typelibs. The advantage is that early binding is much faster, most
errors are found at compile time and all constants (olMailItem in
example) and record types are imported from the typelib.
</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>In any case, use a recent compiler (2.6.0) to get this
working (both late and early binding). Older compilers had some problems with
COM objects.</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012>Ludo</SPAN></FONT></SPAN></DIV>
<DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012> </DIV>
<P class=MsoNormal dir=ltr><FONT face=Arial size=2></FONT><FONT face=Arial
size=2></FONT><BR></P></SPAN></FONT></SPAN>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012></SPAN></FONT></SPAN> </P>
<P class=MsoNormal dir=ltr><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><FONT color=#0000ff><SPAN
class=828293416-07012012> </P></SPAN></FONT></SPAN></BODY></HTML>