代码示例: Form放入TAgent控件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, AgentObjects_TLB;
type
TForm1 = class(TForm)
Agent: TAgent;
Button1: TButton;
Button2: TButton;
Button5: TButton;
Button4: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
AgentLoaded: Boolean;
ThisCharEX: IAgentCtlCharacterEx;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var Loadkey: olevariant;
begin
if AgentLoaded = False then begin
try
Agent.Connected := True;
Agent.Characters.Load('DefChar', LoadKey);
AgentLoaded := True;
ThisCharEx := Agent.Characters['DefChar'];
ThisCharEx.Top := 300;
ThisCharEx.Left := 200;
ThisCharEx.Show(False);
except
AgentLoaded := False;
showmessage('Load Error !');
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if AgentLoaded then ThisCharEX.Speak('Hello !', '');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if AgentLoaded then ThisCharEX.Think('How are You ?');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
//play Events:
//Congratulate_2
//GetAttention
//Greet
//Pleased
//...........
if AgentLoaded then ThisCharEx.Play('Congratulate_2');
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if AgentLoaded then begin
if ThisCharEx.Commands.Count > 0 then ThisCharEx.Commands.RemoveAll;
try
Agent.Characters.Unload('DefChar');
Agent.Connected := False;
AgentLoaded := False;
except
Agent.Characters.Unload('DefChar');
AgentLoaded := False;
end;
end
else showmessage('No Load !');
end;
end.