Home arrow Delphi-Kylix arrow Page 2 - Delphi and Microsoft Agent
DELPHI-KYLIX

Delphi and Microsoft Agent


While writing a letter in MS Word, I accidentally clicked on the help button and this animated little thing on a a bike jumped up and presented me with an input box. I’ve seen it a few times before, but this time I wondered if I could write a program that could animate characters in Delphi.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
November 01, 2006
TABLE OF CONTENTS:
  1. · Delphi and Microsoft Agent
  2. · Using the Agent in Delphi
  3. · Modifying speech out
  4. · Other features of the Agent

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Delphi and Microsoft Agent - Using the Agent in Delphi
(Page 2 of 4 )

Create a Delphi application and drop a TAgent component, a memo and a button:

Now we only need to create and activate the character, which is easy enough to do:

Agent1.active:=true;

But before we do this we need to decide which agent we want to use and then load the agent into the TAgent component like so:

Agent1.characters.load('Merlin','merlin.acs');
Merlin:=Agent1.Characters.Character('Merlin');

To make Merlin read what is in the memo, we would call the Speak() method:

Merlin.speak(memo.text, '')  

Before we make Merlin speak, we have to be able to see him, so we call the Show() method:

Merlin.show();

So, our code should look something like this:

 var
  Form1: TForm1;
 peedy,Merlin:IAgentCtlCharacterEx;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Agent1.characters.load('Merlin','merlin.acs');
Merlin:=Agent1.Characters.Character('Merlin');
Agent1.Connected:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Merlin.show(false);
Merlin.speak(memo1.text, '');
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose:
Boolean);
begin
Agent1.Characters.Unload('Merlin');
end;

Here's a test run of the application:

The code above is fine, insofar as getting Merlin to talk. But it is not very well coded. For example, our application will crash if the user presses button1 while Merlin is busy reading. So we need to make a provision for that. To handle checks like that we make use of the loadrequest method:

loadrequest:=Agent1.characters.load('Merlin','merlin.acs');

So our revised code will look like this:

procedure TForm1.FormShow(Sender: TObject);
begin
loadrequest:=Agent1.characters.load('Merlin','merlin.acs');
if loadrequest.Status <> 0 then begin
//could not load agent
messagedlg('Merlin is already loaded',mtError,[mbOK],0);
exit;
end;
Merlin:=Agent1.Characters.Character('Merlin');
Agent1.Connected:=true;
end;

An alternative to the above code would be to use the try...except block:

try
loadrequest:=Agent1.characters.load('Merlin','merlin.acs');
except on E:Exception do
begin
messagedlg(E.Message,mtError,[mbOK],0);
exit;
end;


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials