Activex OLE Delphi

//eğer Office 2000 kurulu ise MSAgent ActiveX nesnesini Delphi'ye kurabilirsiniz
//artık istediğiniz Ajanı açıp onu kontrol edebilirsiniz...
//www.microsoft.com'dan ayrıntıları bulabilirisiniz...
//En alt kısımda VB5 kodlarını da bulabilirsiniz...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, AgentObjects_TLB, Spin, ComCtrls, ExtCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
Agent1: TAgent;
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Button2: TButton;
Button3: TButton;
CheckBox1: TCheckBox;
Timer1: TTimer;
StatusBar1: TStatusBar;
Label5: TLabel;
Button4: TButton;
OpenDialog1: TOpenDialog;
SpeedButton1: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
c:widestring;d:OleVariant;
implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012;
begin
Begin
ReleaseCapture;
FORM1.perform(WM_SysCommand, SC_DragMove, 0);
End;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
const
CapPanel = 1;
NumPanel = 2;
ScrlPanel = 3;
DatePanel = 4;
begin
with StatusBar1 do
begin
if GetKeyState(VK_CAPITAL) <> 0 then
StatusBar1.Panels[CapPanel].Text := ' CAP'
else
StatusBar1.Panels[CapPanel].Text := '';
if GetKeyState(VK_NUMLOCK) <> 0 then
StatusBar1.Panels[NumPanel].Text := ' NUM'
else
StatusBar1.Panels[NumPanel].Text := '';
if GetKeyState(VK_SCROLL) <> 0 then
StatusBar1.Panels[ScrlPanel].Text := ' SCRL'
else
StatusBar1.Panels[ScrlPanel].Text := '';
StatusBar1.Panels[DatePanel].Text := FormatDateTime(' mmmm D, YYYYY', now);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
c:='Merlin';
agent1.Characters.Load(c, 'merlin.ACS');
Agent1.Characters.Item[c].Set_AutoPopupMenu(True);
Application.HintColor:=claqua;
end;
procedure TForm1.Button1Click(Sender: TObject);
var a :OleVariant;
begin
agent1.Characters.Item[c].MoveTo(strtoint(edit1.text),strtoint(edit2.text),a);
agent1.Characters.Item[c].Play(ComboBox1.Text);
agent1.Characters.Item[c].Think(edit3.text);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Agent1.Characters.Item[c].ShowPopupMenu
(left+button3.left,top+button3.top+button3.height);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
agent1.Characters.Unload(c);
close;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
agent1.Characters.Item[c].Set_SoundEffectsOn(CheckBox1.Checked);
end;
procedure TForm1.Button4Click(Sender: TObject);
var uzanti:string;i:byte;dosyaadi:string;
begin
OpenDialog1.FileName:='';
OpenDialog1.Execute;
if OpenDialog1.FileName<>'' then
begin
dosyaadi:=lowercase(OpenDialog1.FileName);
agent1.Characters.Unload(c);
uzanti:='';c:='';
i:=strlen(pchar(OpenDialog1.FileName));
while (dosyaadi[i]<>'.') do dec(i); //uzanti koparilir
dec(i); //nokta gidiyor
while (dosyaadi[i]<>'\') do begin //sadece adı lazim
uzanti:=dosyaadi[i]+uzanti;
dec(i);
end;
c:=uzanti;
agent1.Characters.Load(c, OpenDialog1.FileName);
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
agent1.ShowDefaultCharacterProperties;
end;
end.
---------------------------------------VB 5 kodları
Dim GenieRequest
Dim RobbyRequest
Dim merlinRequest
Dim Genie
Dim Robby
Dim merlin

Private Sub Command1_Click()
Genie.MoveTo 100, 100
Genie.Show
Robby.MoveTo 250, 100
Robby.Show
Genie.Play "Announce"
Set GenieRequest = Genie.Speak("Tavuk neden karşıya geçti?")
Robby.Wait GenieRequest
Robby.Play "Confused"
Set RobbyRequest = Robby.Speak("Ne biliyim. Sence neden geçti?")
Genie.Wait RobbyRequest
Genie.Play "Pleased"
Set GenieRequest = Genie.Speak("Karşı tarafta olmak için...")

Robby.Wait GenieRequest
Robby.Play "Sad"
Robby.Speak "Hiç sormamalıydım!"
End Sub
Private Sub Command2_Click()
List1.Clear
For Each Animation In Genie.AnimationNames
List1.AddItem (Animation)
Next
End Sub
Private Sub Command3_Click()
Dim strName As String
merlin.MoveTo 400, 100
merlin.Show
merlin.Play "Greet"
merlin.Play "Restpose"
merlin.Speak "Merhaba!"
merlin.Play "Announce"
merlin.Speak "Ben Merlin."
merlin.Play "Pleased"
merlin.Speak "Tanıştığımıza memnun oldum!"
merlin.MoveTo 250, 500
merlin.Speak "Size bazı şeyler göstereceğim..."
merlin.Play "Hide"
merlin.Play "Show"
merlin.Speak "bazı hareketlerimi..."
merlin.Speak "İşte bir sihir numaram!"
merlin.Play "DoMagic1"
merlin.Play "DoMagic2"
merlin.Play "Pleased"
merlin.Play "Restpose"
merlin.Play "Suggest"
merlin.Speak "Şimdi bir önerim var!"
merlin.Speak "İşte lamba ile bunu belirtirim..."
merlin.Play "Pleased"
merlin.Play "Restpose"
merlin.Speak "Okuyabilir..."
merlin.Play "Read"
merlin.Speak "ve yazabilirim."
merlin.Play "Write"
merlin.Play "Pleased"
merlin.Play "Restpose"
merlin.Speak "Teşekkürler"
merlin.Play "Wave"
merlin.Speak "Güle güle..."
merlin.Hide
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Load()
Agent1.Characters.Load "Genie", "genie.acs"
Agent1.Characters.Load "Robby", "robby.acs"
Agent1.Characters.Load "Merlin", "merlin.acs"
Set Genie = Agent1.Characters("Genie")
Set Robby = Agent1.Characters("Robby")
Set merlin = Agent1.Characters("Merlin")
Genie.Get "State", "Showing"
Robby.Get "State", "Showing"
Genie.Get "Animation", "Announce, AnnounceReturn, Pleased,PleasedReturn "

Robby.Get "Animation", "Confused, ConfusedReturn, Sad, SadReturn"
Set Genie = Agent1.Characters("Genie")
Set Robby = Agent1.Characters("Robby")
End Sub
Private Sub List1_Click()
Genie.Stop
Genie.MoveTo Text1.Text, Text2.Text
Genie.Show
Genie.Play List1.Text
Genie.Speak Text4.Text
End Sub