C
coolrain
Unregistered / Unconfirmed
GUEST, unregistred user!
近日做一小程序,不想得到灾难性故障,实让人不爽,愿高手出手。
-------------------------------------------------------------
这是一个关与com的程序,更确切的说,是关与自动化的。
我做了一个进程外的服务,用automation object.放了一上image在上面。
然后做了一个客户端,同样也放了一个image在Form上面。
目地:通过改变客户端的image,同时改变服务端image。
现在现象:
调试能通过,但运行到关键地方时,出现错误。就是这该死的灾难性故障。
Fpicshow.Set_pic(ipic);
就是这一句!!!
另外:
procedure GetOlePicture(Picture: TPicture; var OlePicture: IPicture);//wrong
procedure SetOlePicture(Picture: TPicture; OlePicture: IPictureDisp);
两处定义不符,调试时按ipicture,类型不匹配。
难道帮助有误?
现在现象:
调试能通过,但运行到关键地方时,出现错误。就是这该死的灾难性故障。
以下附上详细代码:(类型库未列出)
----------------server----------------------
unit Unit1;//服务端界面
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
private
{ Private declarations }
public
function GetPic:TPicture;
procedure SetPic(Avalue:TPicture);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.GetPic: TPicture;
begin
Result:=Image1.Picture;
end;
procedure TForm1.SetPic(Avalue: TPicture);
begin
Image1.Picture.Assign(Avalue);
end;
end.
##########
unit pictlb;//服务端接口实现
interface
uses
ComObj, ActiveX, picprj_TLB, StdVcl,AXCtrls,graphics;
type
Tpicshow = class(TAutoObject, Ipicshow)
protected
function Get_pic: IPictureDisp; safecall;
procedure Set_pic(const Value: IPictureDisp); safecall;
{ Protected declarations }
end;
implementation
uses ComServ,Unit1;
function Tpicshow.Get_pic: IPictureDisp;
begin
GetOlePicture(Form1.GetPic,Result);
end;
procedure Tpicshow.Set_pic(const Value: IPictureDisp);
begin
SetOlePicture(Form1.GetPic,value);
end;
initialization
TAutoObjectFactory.Create(ComServer, Tpicshow, Class_picshow,
ciMultiInstance, tmApartment);
end.
#################################
unit Unit1;//客户端
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls,picprj_TLB, ExtDlgs;
type
TForm1 = class(TForm)
Image1: TImage;
ConBt: TButton;
DisBt: TButton;
ChangeBt: TButton;
OpenPictureDialog1: TOpenPictureDialog;
procedure ConBtClick(Sender: TObject);
procedure DisBtClick(Sender: TObject);
procedure ChangeBtClick(Sender: TObject);
private
{ Private declarations }
public
FPicshow:Ipicshow;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses AXCtrls,ActiveX;
{$R *.DFM}
procedure TForm1.ConBtClick(Sender: TObject);
begin
FPicshow:=Copicshow.Create;
end;
procedure TForm1.DisBtClick(Sender: TObject);
begin
FPicshow:=nil;
end;
procedure TForm1.ChangeBtClick(Sender: TObject);
var ipic:IPicturedisp;
begin
if OPenPictureDialog1.Execute then
Image1.Picture.LoadFromFile(openpicturedialog1.FileName);
GetolePicture(Image1.Picture,ipic);
Fpicshow.Set_pic(ipic);
end;
end.