请帮我看看这样使用是否正确?(100分)

  • 主题发起人 主题发起人 akosboy
  • 开始时间 开始时间
A

akosboy

Unregistered / Unconfirmed
GUEST, unregistred user!
一个DLL中这样定义:
// *********************************************************************//
// Interface: IMpRect
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {9009B37F-9FAC-413B-B874-9CCCA0E7AA64}
// *********************************************************************//
IMpRect = interface(IDispatch)
['{9009B37F-9FAC-413B-B874-9CCCA0E7AA64}']
function Get_xmin: Double; safecall;
procedure Set_xmin(pVal: Double); safecall;
function Get_ymin: Double; safecall;
procedure Set_ymin(pVal: Double); safecall;
function Get_xmax: Double; safecall;
procedure Set_xmax(pVal: Double); safecall;
function Get_ymax: Double; safecall;
procedure Set_ymax(pVal: Double); safecall;
procedure Set_(xmin: Double; ymin: Double; xmax: Double; ymax: Double); safecall;
property xmin: Double read Get_xmin write Set_xmin;
property ymin: Double read Get_ymin write Set_ymin;
property xmax: Double read Get_xmax write Set_xmax;
property ymax: Double read Get_ymax write Set_ymax;
end;
*************************************************************
在程序中这样使用:
var
MyRect:IMpRect;
begin
MyRect.Set_xmin(1.0);
MyRect.Set_xMax(2.0);
MyRect.Set_ymin(1.0);
MyRect.Set_ymax(2.0);
**************************************
结果编译没有错误,但程序执行出现如下提示:
Access violation at address 00416618C in module 'Project1.exe'.Read of address 000000.
我刚学用DELPHI,这个问题不知道是因为什么情况造成的,请各位达人指点。
 
没见你使用初始化或创建函数呀?
 
应该有CoMpRect的类吧,用它就对了.
 
有没有使用指针?
 
要先创建实例啊
MyRect:=coMpRect.create;
...
 
TMyMpRect=class(TInterfacedObj, IMpRect)
//与接口部分定义相同
function Get_xmin: Double; safecall;
//...
property ymax: Double read Get_ymax write Set_ymax;
end;

const GUID_MPRect:TGUID ='{9009B37F-9FAC-413B-B874-9CCCA0E7AA64}';

在程序中
var
MyRect:IMpRect;
begin
try
TMyMpRect.Create.QueryInterface(GUID_MPRect, MyRect);
MyRect.Set_xmin(1.0);
MyRect.Set_xMax(2.0);
MyRect.Set_ymin(1.0);
MyRect.Set_ymax(2.0);
except
//raise;
end;
MyRect := nil;
end;
 
呵呵,学会了。新手就是不明白这些:)谢谢各位兄弟了
 
多人接受答案了。
 
后退
顶部