我在类型库编辑器中为一个接口ITest添加属性Name和方法DoSomething,在接口和接口实现类中会自动添加如下声明:
Itest = interface(IDispatch)
['{0E06D364-58CF-4BA2-AC0E-3AB3F8FA22A0}']
procedure DoSomeThing; safecall;
function Get_Name: Integer; safecall;
procedure Set_Name(Value: Integer); safecall;
property Name: Integer read Get_Name write Set_Name;
end;Ttest = class(TAutoObject, Itest)
protected
procedure DoSomeThing; safecall;
function Get_Name: Integer; safecall;
procedure Set_Name(Value: Integer); safecall;end;现在有两个问题不明白:
1、在实现类中Ttest中为何没有声明property Name: Integer read Get_Name write Set_Name?而只有Get_Name和Set_Name声明,那样的话别的类访问这个类时不是没有Name属性了吗?
2、为何在实现类中自动生成的声明会在protected中而不是public,在protected中的话,那这些方法(例如DoSomeThing)对其他类不就是不可见吗?希望懂的朋友解答一下,谢谢!
Itest = interface(IDispatch)
['{0E06D364-58CF-4BA2-AC0E-3AB3F8FA22A0}']
procedure DoSomeThing; safecall;
function Get_Name: Integer; safecall;
procedure Set_Name(Value: Integer); safecall;
property Name: Integer read Get_Name write Set_Name;
end;Ttest = class(TAutoObject, Itest)
protected
procedure DoSomeThing; safecall;
function Get_Name: Integer; safecall;
procedure Set_Name(Value: Integer); safecall;end;现在有两个问题不明白:
1、在实现类中Ttest中为何没有声明property Name: Integer read Get_Name write Set_Name?而只有Get_Name和Set_Name声明,那样的话别的类访问这个类时不是没有Name属性了吗?
2、为何在实现类中自动生成的声明会在protected中而不是public,在protected中的话,那这些方法(例如DoSomeThing)对其他类不就是不可见吗?希望懂的朋友解答一下,谢谢!
解决方案 »
- 既有32位也有64位系统的delphi软件怎么升级啊
- 如何在twebbrowser中可视化获取xpath,即获取鼠标所在位置的xpath
- 要怎么样写这样的查询
- 如何取得某一个网站 (IP)上的系统时间?给点代码,用socket也可以
- 求一DELPHI操作MYSQL数据库的小例子
- 谁知道哪里可以下载 dxdraw for delphi 6 以上版本的???
- 怎样在DLL种共享TDATABASE???
- 如何实现Query的跨库查询?
- 谁有作过MIDAS、DCOM的开发,哪里有MIDAS、DCOM的资料,能提供点吗?
- 如何编程序输出在指定范围内的三个随机数
- 如何将listview中的内容从服务器端发送给客户端,并显示在客户端的LISTVIEW中?
- 有没有能把Unit能整合到工程的工具
2. 客户端是以接口的方式(而不是类)调用ITest,所以可以访问接口里面的任何方法。
Ttest继承自Itest 所以也是有Name的
只是需要一个类型转换
var
test:Ttest;
G:Itest;
begin
test:=Ttest.Create;
G:=t as Itest;
ShowMessage(IntToStr(G.Name));
test.free;
end;
protected 声明的方法 在他的子类中是可以用的
G:=test as Itest;