Solved

What is the Ms Agent command for Clipboard

Posted on 2001-08-21
7
212 Views
Last Modified: 2010-04-06
Hello
anyone know what the Ms Agent command is for reading from the windows clipboard
sample code required thanks
0
Comment
Question by:neopolis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:RickHalle
ID: 6410592
Need to know what you are using for the agent first. There are a few agent controls available for Delphi which may make a difference here. If you are using the Control directly without a third party wrapper then I may be able to come up with something.

Rick Halle
0
 

Author Comment

by:neopolis
ID: 6410644
Hello Rick

I am using Microsoft ActiveX control

Below is my code
---------------------------------

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Agent1: TAgent;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  MyAgent: IAgentCtlCharacterEx;


implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
Agent1.Characters.Load('myagent', 'c:\WINDOWS\MSagent\Chars\genie.acs');
MyAgent := Agent1.Characters.Character('myagent');
MyAgent.Show(0);


//THIS IS WHERE THE AGENT SPEAKS

//instead of him speaking the words 'look i can speak'
//i want him to speak from the windows clipboard


MyAgent.Speak('Look! I can speak!','');


end;

end.



//Rick because i am new in delphi
you may have to fill in the above code for me
Uses etc
thanks Neopolis


0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6410743
Let's start with the following.

Change:
Old:Agent1.Characters.Load('myagent', 'c:\WINDOWS\MSagent\Chars\genie.acs');
New:Agent1.Characters.Load('myagent', 'genie.acs');

It should run this way. If you find you have a path problem then copy the acs to the project directory. You can't count on the control being in any particular place. (Mine errored right away because my OS is on F: Drive)

Change:
Old:MyAgent.Show(0);
New:MyAgent.Show(False);//Show Fast(True/False)

What you have works but True/False will be easier to remember.

In the Destroy Event for the form add the following:

procedure TForm1.FormDestroy(Sender: TObject);
begin
  if MyAgent <> nil then
    begin
    MyAgent.Hide(False); //Hide The Agent
    MyAgent.StopAll(''); //Stop Any Pending Actions
    Agent1.Characters.Unload('myagent'); //Unload the Character
  end;
end;

This should ensure the agent gets unloaded. This can also be used to unload in your app.

I will see what I can come up with for the clipboard.

Rick Halle

BTW: Your code for opening the agent is essentially the same as what I am using currently and I did not need to add or change the units clause.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:neopolis
ID: 6410804
I will try this now *smiles*
0
 
LVL 2

Accepted Solution

by:
RickHalle earned 10 total points
ID: 6410814
Got it now:

Add ClipBrd to the uses clause.

Now use the following for Button1Click.

procedure TForm1.Button1Click(Sender: TObject);
var
  CBHandle: THandle;
  TextPtr: PChar;
  ClipBoardText: string;
begin
  if MyAgent = nil then//Make sure not yet loaded
  begin
    Agent1.Characters.Load('myagent', 'genie.acs');
    MyAgent := Agent1.Characters.Character('myagent');
  end;
  MyAgent.Show(False);//Show Fast(True/False)

  ClipBoard.Open;
  try
    CBHandle := Clipboard.GetAsHandle(CF_TEXT);
    TextPtr := GlobalLock(CBHandle);
    ClipBoardText := StrPas(TextPtr);
    GlobalUnlock(CBHandle);
  finally
    Clipboard.Close;
  end;
// Make sure there is some text
  if Length(ClipBoardText) <> 0 then
    MyAgent.Speak(ClipBoardText, '');
end;

I also added a check to see if the agent was already loaded when you click the button. Otherwise it will throw an error. Additionally it checks the clipboard text to insure there actually is some before speaking. Otherwise it will throw an error if there is none.

Rick Halle
0
 

Author Comment

by:neopolis
ID: 6410857
Am trying this now, yes i like the way the form destroy scloses everything fast back soon.
0
 

Author Comment

by:neopolis
ID: 6410875
unreal Rick i would have been here forever trying to work that out, it works very nicely...Thank you very very much
my email add is   neopolisoz@yahoo.com.au  if you want you can write me there i would like to send you some Post cards from Australiaas a further appreciation *smiles*

thanks again
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question