Membuka Internet Explorer dengan OLE
uses comobj;
procedure OpenIE(aURL: string);
var
IE: Variant;
WinHanlde: HWnd;
begin
if (VarIsEmpty(IE)) then
begin
IE := CreateOleObject(’InternetExplorer.Application’);
IE.Visible := True;
IE.Navigate(aURL);
end
else
begin
WinHanlde := FindWindow(’IEFrame’, nil);
if (0 <> WinHanlde) then
begin
IE.Navigate(aURL);
SetForegroundWindow(WinHanlde);
end
else
ShowMessage(’Can”t open IE !’);
end;
end;
Check if Word, Excel, Access, Outlook, Powerpoint is running
uses
ComObj, ActiveX;
function IsObjectActive(ClassName: string): Boolean;
var
ClassID: TCLSID;
Unknown: IUnknown;
begin
try
ClassID := ProgIDToClassID(ClassName);
Result := GetActiveObject(ClassID, nil, Unknown) = S_OK;
except
Result := False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsObjectActive(’Word.Application’) then ShowMessage(’Word is running !’);
if IsObjectActive(’Excel.Application’) then ShowMessage(’Excel is running !’);
if IsObjectActive(’Outlook.Application’) then ShowMessage(’Outlook is running !’);
if IsObjectActive(’Access.Application’) then ShowMessage(’Access is running !’);
if IsObjectActive(’Powerpoint.Application’) then ShowMessage(’Powerpoint is running !’);
end;
Send an e-mail through Outlook
uses
ComObj;
procedure TForm1.Button16Click(Sender: TObject);
const
olMailItem = 0;
olByValue = 1;
var
OutlookApp, MailItem, MyAttachments: OLEVariant;
begin
try
OutlookApp := GetActiveOleObject(’Outlook.Application’);
except
OutlookApp := CreateOleObject(’Outlook.Application’);
end;
try
MailItem := OutlookApp.CreateItem(olMailItem);
MailItem.Recipients.Add(’YourMailAddress@something.com’);
MailItem.Subject := ‘Your Subject’;
MailItem.Body := ‘Your Message’;
myAttachments := MailItem.Attachments;
myAttachments.Add(’C:\text.txt’, olByValue, 1, ‘Name of Attachment’);
MailItem.Send;
finally
myAttachments := VarNull;
OutlookApp := VarNull;
end;
end;