怎样才能等ms agent 做完动作才执行下一条代码.

atyzy 2002-12-09 07:03:11
比如说,我想让ms agent说一段话,说完了,我再显示一个msg.

peedy.speak(....);
showmessage(...);

可是,没等话说完呢,msg就出来了.我试过用robby等待,可是只是他们角色之间的等待.msg一点不停.
高手请帮忙.
谢谢!
...全文
49 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
INeedCa 2002-12-23
  • 打赏
  • 举报
回复
刚才试了一下,供你参考
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, AgentObjects_TLB;

type
TDoAfterAgentBusy = procedure of object;

TForm1 = class(TForm)
Agent1: TAgent;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Agent1Command(ASender: TObject; const UserInput: IDispatch);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure Agent1IdleStart(ASender: TObject;
const CharacterID: WideString);
procedure Button3Click(Sender: TObject);
private
FDoAfterAgent : TDoAfterAgentBusy;

//The TDoAfterAgentBusy Param for
FvarParam :Variant;
//
{ Private declarations }
procedure DoAfterAgentTalk;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
var

Genie: IAgentCtlCharacterEx;
Request1: IAgentCtlRequest;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Genie.Commands.Add('1','Yes','',True,True);
Genie.Commands.Add('2','No','',True,True);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//Just for test
Request1:= Agent1.Characters.Load('Genie1','c:\windows\msagent\chars\merlin.acs');
Genie:= IAgentCtlCharacterEx(Agent1.Characters.Character('Genie1'));
Genie.Show(0);
//
end;

procedure TForm1.Agent1Command(ASender: TObject;
const UserInput: IDispatch);
begin
if IAgentCtlUserInput(UserInput).Name = '1' then begin
ShowMessage('Yes');
end
else if IAgentCtlUserInput(UserInput).Name = '2' then begin
ShowMessage('No');
end
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Genie.Hide(1);
Agent1.Characters.Unload('Genie1');
Action:= caFree;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Genie.Speak('Hello', '');
Self.FvarParam := 'After Genie say hello';
Self.FDoAfterAgent := Self.DoAfterAgentTalk;
end;

procedure TForm1.DoAfterAgentTalk;
begin
try
ShowMessage(VarToStr(FvarParam));
except
//TODO: fuck error param
end;
end;

procedure TForm1.Agent1IdleStart(ASender: TObject;
const CharacterID: WideString);
begin
if assigned(Self.FDoAfterAgent) then
begin
Self.FDoAfterAgent();

Self.FDoAfterAgent := nil;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Self.FvarParam := 'After Genie say hehe';
Self.FDoAfterAgent := Self.DoAfterAgentTalk;
Genie.Speak('Hehe', '');
end;

end.
atyzy 2002-12-15
  • 打赏
  • 举报
回复
halfdream(哈欠) :能否仔细说说.我是菜鸟
halfdream 2002-12-13
  • 打赏
  • 举报
回复
peedy.speak(....);
MS AGENT控制的这些动作都是异步调用,调用后立即返回,不会等待
AGENT执行动作的.

可以考虑在AGENT的事件中处理,比如试试OnIdleStart之类的事件.
netrobo 2002-12-10
  • 打赏
  • 举报
回复
不太明白!
atyzy 2002-12-10
  • 打赏
  • 举报
回复
我是初学者,进程一类的东西我一看就自卑.

stanely(俺是邢她汉子):不光要wait其它agent的动作,还要wait showmessage()

stanely 2002-12-09
  • 打赏
  • 举报
回复
好像可以通过2个agent来实现,因为每个agent提供wait功能,但是只能wait其他的agent完成动作。

blucecat 2002-12-09
  • 打赏
  • 举报
回复
没懂起你的意思,如果你想等待进程结束,你可以用下面两个函数中的任意一个
function WinExecAndWait32_v1(FileName: string; Visibility: integer):
Cardinal; {integer}
var
zAppName: array[0..512] of char;
zCurDir: array[0..255] of char;
WorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
StrPCopy(zAppName, FileName);
GetDir(0, WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
if not CreateProcess(nil,
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
true, { handle inheritance flag }
CREATE_NEW_CONSOLE or { creation flags }
NORMAL_PRIORITY_CLASS,
nil, { pointer to new environment block }
nil, { pointer to current directory name, PChar}
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) { pointer to PROCESS_INF }
then Result := INFINITE {-1} else
begin
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
CloseHandle(ProcessInfo.hProcess); { to prevent memory leaks }
CloseHandle(ProcessInfo.hThread);
end;
end;
function WinExecAndWait32_v2(FileName: string; Visibility: integer):
Cardinal; {integer}
var
zAppName: array[0..512] of char;
zCurDir: array[0..255] of char;
WorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
Msg: TagMsg;
ExitCode: cardinal;
begin
StrPCopy(zAppName, FileName);
GetDir(0, WorkDir);
StrPCopy(zCurDir, WorkDir);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW; // STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := Visibility;
if CreateProcess(nil, { and once more: }
zAppName, { pointer to command line string }
nil, { pointer to process security attributes }
nil, { pointer to thread security attributes }
false, { handle inheritance flag }
NORMAL_PRIORITY_CLASS, { creation flags }
nil, { pointer to the new environment block }
nil, { current directory name }
StartupInfo, { pointer to STARTUPINFO }
ProcessInfo) then { pointer to PROCESS_INF }
begin
repeat
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
begin
if (Msg.message = WM_QUIT) then
Result := Msg.wParam;
TranslateMessage(msg);
Dispatchmessage(msg);
Sleep(100); {your choice}
end;
GetExitCodeProcess(ProcessInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
Result := 0;
end
else begin
Result := GetLastError;
end;
end;

5,387

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧