delphi调用com 为什么会出现“不支持此接口”的错误! (50分)

  • 主题发起人 主题发起人 gyx999
  • 开始时间 开始时间
G

gyx999

Unregistered / Unconfirmed
GUEST, unregistred user!
调用com project2.MyMath,出现“不支持此接口”的错误!是何原因?
procedure TForm1.Button1Click(Sender: TObject);
var s:OleVariant;
begin
s:=CreateOleObject('project2.MyMath');
end;
 
http://www.wideman-one.com/gw/tech/Delphi/autointf/
 
It is very easy. The way you can do late binding in Delphi is generally by using OleVariant variables.
By using typed variables you are using early binding. This is a snippet of code from the unit fMainForm.pas
in the WordProcessor directory:

implementation
uses ComObj;
{$R *.DFM}
procedure TForm1.bLateBindingClick(Sender: TObject);
var myobj :
OleVariant;
begin
myobj := CreateOLEObject('COMCOnverter.ConverterList');
end;

As you can see, the only differences between the two are the type of myobj and the instantiation of it.

The fact that you declared myobj as an OleVariant is the key here. That tells Delphi how you invoke the
methods of a COM object. Anytime you use an OleVariant you can specify any method name. The compiler won't
complain. Try putting myobj.XYZ in the first event handler. Delphi will successfully compile it but at
runtime will raise an exception as soon as you hit that line of code. Late binding .
In the second case you wouldn't be able to compile it, because IConverterList doesn't define have a method
called XYZ. Early binding .
 
tks.but sorry,I cannot see any difference between them!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
583
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部