* * * *

Privacy Policy

Blog italiano

Clicca qui se vuoi andare al blog italiano su Lazarus e il pascal.

Forum ufficiale

Se non siete riusciti a reperire l'informazione che cercavate nei nostri articoli o sul nostro forum vi consiglio di visitare il
Forum ufficiale di Lazarus in lingua inglese.

Lazarus 1.0

Trascinare un file nel programma
DB concetti fondamentali e ZeosLib
Recuperare codice HTML da pagina web
Mandare mail con Lazarus
Stabilire il sistema operativo
Esempio lista in pascal
File INI
Codice di attivazione
Realizzare programmi multilingua
Lavorare con le directory
Utilizzare Unità esterne
TTreeView
TTreeview e Menu
Generare controlli RUN-TIME
LazReport, PDF ed immagini
Intercettare tasti premuti
Ampliare Lazarus
Lazarus e la crittografia
System Tray con Lazarus
UIB: Unified Interbase
Il file: questo sconosciuto
Conferma di chiusura di un applicazione
Liste e puntatori
Overload di funzioni
Funzioni a parametri variabili
Proprietà
Conversione numerica
TImage su Form e Panel
Indy gestiore server FTP lato Client
PopUpMenu sotto Pulsante (TSpeedButton)
Direttiva $macro
Toolbar
Evidenziare voci TreeView
Visualizzare un file Html esterno
StatusBar - aggirare l'errore variabile duplicata
Da DataSource a Excel
Le permutazioni
Brute force
Indy 10 - Invio email con allegati
La gestione degli errori in Lazarus
Pascal Script
Linux + Zeos + Firebird
Dataset virtuale
Overload di operatori
Lavorare con file in formato JSON con Lazarus
Zeos ... dietro le quinte (prima parte)
Disporre le finestre in un blocco unico (come Delphi)
Aspetto retrò (Cmd Line)
Lazarus 1.0
Come interfacciare periferica twain
Ubuntu - aggiornare free pascal e lazarus
fpcup: installazioni parallele di lazarus e fpc
Free Pascal e Lazarus sul Raspberry Pi
Cifratura: breve guida all'uso dell'algoritmo BlowFish con lazarus e free pascal.
Creare un server multithread
guida all'installazione di fpc trunk da subversion in linux gentoo
Indice
DB concetti fondamentali e connessioni standard
Advanced Record Syntax
DB concetti fondamentali e DBGrid
DB concetti fondamentali e TDBEdit, TDBMemo e TDBText
Advanced Record Syntax: un esempio pratico
Superclasse form base per programmi gestionali (e non)
Superclasse form base per programmi gestionali (e non) #2 - log, exception call stack, application toolbox
Superclasse form base per programmi gestionali (e non) #3 - traduzione delle form
Superclasse form base per programmi gestionali (e non) #4 - wait animation
Un dialog per la connessione al database:TfmSimpleDbConnectionDialog
Installare lazarus su mac osx sierra
immagine docker per lavorare con lazarus e free pascal
TDD o Test-Driven Development
Benvenuto! Effettua l'accesso oppure registrati.
Aprile 30, 2024, 04:12:16 pm

Inserisci il nome utente, la password e la durata della sessione.

233 Visitatori, 0 Utenti

Autore Topic: Office Automation con Outlook  (Letto 7502 volte)

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Office Automation con Outlook
« il: Luglio 26, 2012, 10:33:14 am »
Per svariate necessità avrei bisogno di interfacciarmi ad un Outlook ( quindi ovviamente solo su Windows ) e agire sulla rubrica.

Ho cercato un po' di informazioni e ho trovato questo esempio che serve a mandare un email:

Codice: [Seleziona]
uses ComObj;

...

procedure TForm1.Button1Click(Sender: TObject);
const olMailItem=0;

var Mail,Message:variant;

 

begin
  // attach to running outlook
  // Mail:=GetActiveOleObject('Outlook.Application');
  // open Outlook
  Mail:=CreateOleObject('Outlook.Application');
  Message:=Mail.CreateItem(olMailItem);
  Message.Recipients.Add('first at recipient');
  Message.Recipients.Add('second at recipient');
  Message.Subject:= 'This is the subject';
  Message.Body:= 'Hi from lazarus';
  Message.CC:='cc at recipient';
  Message.Attachments.Add('C:\lazarus\readme.txt') ;
  Message.Send();
end;

Poi suggeriscono di usare le documentazioni per VB/VBA che sono decisamente più facili da trovare e adattarle esempio questo
http://support.microsoft.com/kb/220595/it

Però non ho le costanti, non so se devo aggiungere la libreria "MSOUTL.OLB" come riferimento o cosa, ad esempio si pianta giustamente arrivando al
Codice: [Seleziona]
Set olItem = olApp.CreateItem(olContactItem)
che non trova "olContactItem"

Potrei fare tutto in VB e via, ma se possibile volevo farlo con Lazarus.
Avete qualche esperienza in merito?

Grazie.

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Re:Office Automation con Outlook
« Risposta #1 il: Luglio 26, 2012, 10:37:50 am »
Intanto qui ho trovato il valore della costante "olContactItem" che sembra essere 2
http://technet.microsoft.com/en-us/library/ee692870

nomorelogic

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2870
  • Karma: +20/-4
Re:Office Automation con Outlook
« Risposta #2 il: Luglio 26, 2012, 03:42:08 pm »
le costanti le devi dichiarare tu nella unit
oggi sei fortunato ;)


Codice: [Seleziona]
const
   // items
   olMailItem        = 0;
   olAppointmentItem = 1;
   olContactItem     = 2;
   olTaskItem        = 3;
   olJournalItem     = 4;
   // folder
   olFolderCalendar                 =  9; // The Calendar folder.
   olFolderContacts                 = 10; // The Contacts folder.
   olFolderTasks                    = 13; // The Tasks folder.
   olFolderConflicts                = 19; // The Conflicts folder (subfolder of Sync Issues folder). Only available for an Exchange account.
   olFolderDeletedItems             =  3; // The Deleted Items folder.
   olFolderDrafts                   = 16; // The Drafts folder.
   olFolderInbox                    =  6; // The Inbox folder.
   olFolderJournal                  = 11; // The Journal folder.
   olFolderJunk                     = 23; // The Junk E-Mail folder.
   olFolderLocalFailures            = 21; // The Local Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
   olFolderManagedEmail             = 29; // The top-level folder in the Managed Folders group. For more information on Managed Folders, see Help in Microsoft Outlook. Only available for an Exchange account.
   olFolderNotes                    = 12; // The Notes folder.
   olFolderOutbox                   =  4; // The Outbox folder.
   olFolderSentMail                 =  5; // The Sent Mail folder.
   olFolderServerFailures           = 22; // The Server Failures folder (subfolder of Sync Issues folder). Only available for an Exchange account.
   olFolderSyncIssues               = 20; // The Sync Issues folder. Only available for an Exchange account.
   olFolderToDo                     = 28; // The To Do folder.
   olPublicFoldersAllPublicFolders  = 18; // The All Public Folders folder in the Exchange Public Folders store. Only available for an Exchange account.
   olFolderRssFeeds                 = 25; // The RSS Feeds folder.
   // field type
   olText = 1;

   // attachments
   wdStory = 6;

Imagination is more important than knowledge (A.Einstein)

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Re:Office Automation con Outlook
« Risposta #3 il: Luglio 26, 2012, 04:47:58 pm »
Ho messo questo:
Codice: [Seleziona]
const
  olFolderContacts=10;
...
procedure TfrmMain.Button1Click(Sender: TObject);
var
  olApp, olNs, olContacts: OleVariant;
  Each: Integer;

begin
  olApp:=CreateOleObject('Outlook.Application');
  olNs:=olApp.GetNamespace('MAPI');
  olNs.Logon;
  olContacts:=olNs.GetDefaultFolder(olFolderContacts).Items;
  for Each:=1 to olContacts.Count do
  begin
    ShowMessage(olContacts.Item[Each].FullName);
  end;
end;

Se faccio uno ShowMessage di olContacts.Count mi riporta il numero corretto dei contatti ma quando vado a stampare la proprietà FullName mi dice
Citazione
raised exception class 'EOleSysError' parametro non corretto

nomorelogic

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2870
  • Karma: +20/-4
Re:Office Automation con Outlook
« Risposta #4 il: Luglio 26, 2012, 05:07:56 pm »
lavorare con Ole non è facile...

prova qualcosa del genere e vedi se riesci a leggere i campi:

Codice: [Seleziona]
var 
   itmContact, itmProperty: OleVariant;
   ScanProp: integer;
   sName, sValue: string;
begin
...
    itmContact:= olContacts.Items[scan];
    for ScanProp := 0 to itmContact.ItemProperties.Count - 1 do
       begin
             itmProperty := itmContact.ItemProperties.Item[ScanProp];
             sName  := itmProperty.Name;
             sValue := VarToStr( itmProperty.Value );
...


Imagination is more important than knowledge (A.Einstein)

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Re:Office Automation con Outlook
« Risposta #5 il: Luglio 27, 2012, 07:40:02 am »
Mi dice parametro non corretto già subito su
Codice: [Seleziona]
itmContact:= olContacts.Item[Each];

E se faccio così:
Codice: [Seleziona]
itmContact:=olContacts;

Alla riga:
Codice: [Seleziona]
for ScanProp := 0 to itmContact.ItemProperties.Count - 1 do

Dice:
Citazione
Method 'ItemProperties' is not supported by automation object
« Ultima modifica: Luglio 27, 2012, 07:48:23 am da Fabio »

nomorelogic

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2870
  • Karma: +20/-4
Re:Office Automation con Outlook
« Risposta #6 il: Luglio 27, 2012, 09:21:42 am »
strano, quello che ti ho postato era codice delphi che a me funziona e il messaggio "Method 'ItemProperties' is not supported by automation object" mi spiazza un po'.

Quando sviluppavo quella unit comunque facevo delle prove in vbs per vedere la sintassi, poi proprietà e metodi erano gli stessi che usavo in delphi.
Prova a vedere con vbs, ci sono un mare di esempi in giro.
Imagination is more important than knowledge (A.Einstein)

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Re:Office Automation con Outlook
« Risposta #7 il: Luglio 27, 2012, 04:00:39 pm »
Mah guarda alla fine per l'utilità che avevo ho risolto in 20min facendolo in VBS, peccato perchè volevo farlo in Lazarus ma ci stavo mettendo troppo tempo tra cercare documentazione e codici funzionanti.

Grazie ugualmente.

nomorelogic

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2870
  • Karma: +20/-4
Re:Office Automation con Outlook
« Risposta #8 il: Luglio 28, 2012, 10:15:51 am »
Mi dice parametro non corretto già subito su
Codice: [Seleziona]
itmContact:= olContacts.Item[Each];

l'ho visto solo ora, la proprietà è "Items" e non "Item"
Imagination is more important than knowledge (A.Einstein)

Fabio

  • Full Member
  • ***
  • Post: 106
  • Karma: +0/-0
Re:Office Automation con Outlook
« Risposta #9 il: Luglio 28, 2012, 04:07:51 pm »
Vado a memoria che ora non ce l'ho sotto mano ma con Items mi diceva proprio che non esisteva la proprietà.
Te lo confermo eventualmente lunedì che sono in ufficio e ho di nuovo quel codice.

 

Recenti

How To

Utenti
Stats
  • Post in totale: 18781
  • Topic in totale: 2235
  • Online Today: 272
  • Online Ever: 900
  • (Gennaio 21, 2020, 08:17:49 pm)
Utenti Online
Users: 0
Guests: 233
Total: 233

Disclaimer:

Questo blog non rappresenta una testata giornalistica poiché viene aggiornato senza alcuna periodicità. Non può pertanto considerarsi un prodotto editoriale ai sensi della legge n. 62/2001.