首页  编辑  

Agent Control使用

Tags: /超级猛料/COM、ActiveX,DDE/   Date Created:
MS Agent对象的使用
插入菜单
...insert PopUp-menu items for MS Agent component?
Author: Manfred Ruzicka  
procedure TForm1.FormCreate(Sender: TObject);
begin
 Agent1.Characters.Load('Merlin', 'merlin.acs');
 with Agent1.Characters.Item['Merlin'] do
 begin
   Show(0);
   Commands.Add('Test', '&Test', 1, 1, True);
   Commands.Add('Demo', '&Demo', 1, 1, True);
 end;
end;

procedure TForm1.Agent1Command(ASender: TObject;
 const UserInput: IDispatch);
var
 Cmd: IAgentCtlUserInput;
begin
 Cmd := UserInput as IAgentCtlUserInput;
 if Cmd.Name = 'Test' then
   Agent1.Characters.Item['Merlin'].Speak('Test', '')
 else if Cmd.Name = 'Demo' then
   Agent1.Characters.Item['Merlin'].Speak('Demo', '');
end;
返回Agent对象所支持的所有动作
uses..., ActiveX;
private
  Req: IAgentCtlRequest;
  Character: IAgentCtlCharacterEx;
  AnimationNames: IAgentCtlAnimationNames;
 
procedure AgentAnimationEnum;
 procedure TForm1.FormCreate(Sender: TObject);
 begin
   Agent1.Characters.Load('Char', 'merlin.acs');
   Character := Agent1.Characters.Character('Char') as IAgentCtlCharacterEx;
   AgentAnimationEnum;
 end;
 procedure TForm1.AgentAnimationEnum;
 var
   AEnum: IEnumVariant;
   Fetch: Cardinal;
   V: OleVariant;
 begin
   AnimationNames := Character.AnimationNames;
   AEnum          := AnimationNames.Enum as IEnumVariant;
   AEnum.Reset;
   ListBox1.Items.Clear;
   repeat
     AEnum.Next(1,V, Fetch);
     if VarToStr(V) <> EmptyStr then
       ListBox1.Items.Add(V);
   until Fetch = 0;
 end;

agent.zip (9.2KB)