代码如下:
unit Unitword;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,comobj, cxLookAndFeelPainters, cxMemo, cxControls, cxContainer,
cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, StdCtrls,
cxButtons, DB, ADODB, DBClient, MConnect;
type
TForm1 = class(TForm)
cxButton1: TcxButton;
cxDateEdit1: TcxDateEdit;
cxMemo1: TcxMemo;
cxTextEdit1: TcxTextEdit;
cxDateEdit2: TcxDateEdit;
Label1: TLabel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
DCOMConnection1: TDCOMConnection;
ClientDataSet1: TClientDataSet;
cxButton2: TcxButton;
procedure cxButton1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure cxButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.cxButton1Click(Sender: TObject);
var outlookapp,mapi,mail,myitem:variant;
s :string;
count,i:integer;
begin
count:=0;
try
//创建outlook对象
outlookapp:=createoleobject('outlook.application');
//分配姓名空间
mapi:=outlookapp.getnamespace('MAPI');
//遍历outlook文件夹,找到'已发送的邮件'文件夹
mail:=mapi.Folders('个人文件夹').Folders('已发送的邮件');
except
on E: Exception do
begin
messagedlg(E.Message, mtError, [mbok], 0 );
end;//end of on E: do
end;//end try..except
for i := 1 to mail.Items.count do
begin
myitem := mail.Items;
if (CheckBox1.Checked = true) and (myitem.SenderName = trim(cxTextEdit1.Text)) then
begin
if myitem.SenderName = trim(cxTextEdit1.Text) then
begin
count:=count+1;
s := s+'第 '+inttostr(count)+' 封:';
s := s+#13+#13+'发件人:'+myitem.sendername;
s := s+#13+#13+'收件人:'+vartostr(myitem.Recipients[1].address);
s := s+#13+#13+'主题: '+myitem.subject;
s := s+#13+#13+'发送时间:'+datetimetostr(myitem.CreationTime);
s := s+#13+#13+'内容:'+#13+#13+myitem.body;
s := s+#13+#13+'大小:'+inttostr(myitem.Size)+'byte'+#13+#13;
end;//end if ..then
end//end if ..then begin
else if (CheckBox2.Checked = true) then
begin
if (myitem.CreationTime >= cxDateEdit1.Text)
and(myitem.CreationTime <= cxDateEdit2.Text) then //?第一处问题所在!!
begin
count:=count+1;
s := s+#13+'第 '+inttostr(count)+' 封:';
s := s+#13+#13+'发件人:'+myitem.sendername;
s := s+#13+#13+'收件人:'+vartostr(myitem.Recipients[1].address);
s := s+#13+#13+'主题: '+myitem.subject;
s := s+#13+#13+'发送时间:'+datetimetostr(myitem.CreationTime);
s := s+#13+#13+'内容:'+#13+#13+myitem.body;
s := s+#13+#13+'大小:'+inttostr(myitem.Size)+'byte'+#13+#13;
end; //end if ..then
end//end else if..
else if ((CheckBox1.Checked = true)and(CheckBox2.Checked = true)) then //?第二处问题所在!!
begin
if ((myitem.CreationTime >= cxDateEdit1.Text)
and (myitem.CreationTime <= cxDateEdit2.Text)
and (myitem.SenderName=cxTextEdit1.Text)) then
begin
count:=count+1;
s := s+'第 '+inttostr(count)+' 封:';
s := s+#13+#13+'发件人:'+myitem.sendername;
s := s+#13+#13+'收件人:'+vartostr(myitem.Recipients[1].address);
s := s+#13+#13+'主题: '+myitem.subject;
s := s+#13+#13+'发送时间:'+datetimetostr(myitem.CreationTime);
s := s+#13+#13+'内容:'+#13+#13+myitem.body;
s := s+#13+#13+'大小:'+inttostr(myitem.Size)+'byte'+#13+#13;
end;//end if ..then
end;//end else if };
cxMemo1.Lines.Text:=s;
oulookapp := Unassigned;
end;
end;