//Automation Object
unit Unit1;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, Project1_TLB, StdVcl, ExtDlgs, Graphics, AxCtrls;
type
TDemo = class(TAutoObject, IDemo)
protected
function Get_Picture: IPicture
safecall;
end;
implementation
uses ComServ;
function TDemo.Get_Picture: IPicture;
var
OpenPictureDialog:TOpenPictureDialog;
FPicture:TPicture;
Ip:IPictureDisp;
begin
OpenPictureDialog:=TOpenPictureDialog.Create(nil);
FPicture:=TPicture.Create;
try
if OpenPictureDialog.Execute then
begin
FPicture.LoadFromFile(OpenPictureDialog.FileName);
GetOlePicture(FPicture,Ip);
Result:=Ip as IPicture;
end;
finally
FPicture.Free;
OpenPictureDialog.Free;
end;
end;
initialization
TAutoObjectFactory.Create(ComServer, TDemo, Class_Demo,
ciMultiInstance, tmApartment);
end.
//调用Automation Object.
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ActiveX, AxCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Project1_TLB;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
FDemo
emo;
begin
FDemo:=CoDemo.Create;
try
SetOlePicture(Image1.Picture,FDemo.Picture as IPictureDisp);
finally
FDemo:=nil;
end;
end;
end.