给个 IPicture 的例子, 不知道怎么样用。 ( 积分: 100 )

  • 主题发起人 主题发起人 let_it_be
  • 开始时间 开始时间
L

let_it_be

Unregistered / Unconfirmed
GUEST, unregistred user!
用在自己的 ActiveX 控件中。
 
用在自己的 ActiveX 控件中。
 
//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:Demo;
begin
FDemo:=CoDemo.Create;
try
SetOlePicture(Image1.Picture,FDemo.Picture as IPictureDisp);
finally
FDemo:=nil;
end;
end;

end.
 
function GetPicture():IPictureDisp;
var
pic:TPicture;
filename:String;
begin
result:=nil;
pic:=TPicture.Create;
try
try
filename:='*.ico';
if fileExists(filename) then
begin
pic.LoadFromFile(filename);
GetOlePicture(pic,result);
end;
Except
result:=nil;
end;
finally
pic.Free;
end;
end;
 
后退
顶部