我想将列表中的联系人显示到 TListBox 上。我在运行 Delphi XE 的 Windows 7 PC 上安装并运行了 Communicator。我正在使用 CommunicatorAPI_TLB 和 CommunicatorPrivate_TLB。
我单击登录和注销按钮,程序按预期运行:我的 Communicator 登录和注销。凉爽的。
问题是当我尝试单击列表用户按钮时。该Contacts.Count
方法似乎给我带来了访问冲突。我在小组中尝试过,结果相同。谁能发现我做错了什么?
{ This IMessenger3 Class Inherits from the IMessenger2 interface -> IMessenger... }
Communicator : IMessenger3;
Contacts : IMessengerContacts;
Contact : IMessengerContact;
Groups : IMessengerGroups;
Connected : Boolean;
End;
Var
frmMain: TfrmMain;
Implementation
{$R *.dfm}
{ ---------------------------------------------------------------------------- }
Procedure TfrmMain.FormCreate(Sender: TObject);
Begin
Communicator := CoMessenger.Create;
End; { FormCreate Procedure }
Procedure TfrmMain.btnSignInClick(Sender: TObject);
Begin
Communicator.AutoSignin;
Connected := True;
End; { btnSignInClick Procedure }
Procedure TfrmMain.btnSignOutClick(Sender: TObject);
Begin
Communicator.Signout;
Connected := False;
End; { btnSignOutClick Procedure }
Procedure TfrmMain.btnLoadContactsClick(Sender: TObject);
Var
ContactIndex : Integer;
Begin
{ Load my contacts into a listbox }
Contacts := IMessengerContacts (Communicator.MyContacts);
Groups := IMessengerGroups (Communicator.MyGroups);
If (Contacts <> Nil) Then Begin
try
showmessage (inttostr(Groups.Count));
showmessage (inttostr(Contacts.count));
except
end;
(*
For ContactIndex := 0 To (Contacts.Count) Do Begin
Contact := IMessengerContact (Contacts.Item (ContactIndex));
{ Add the contact to the list }
lbxContacts.AddItem (Contact.FriendlyName, Nil);
End; { For }
*)
End; { If <> Nil }
End;