在线等待!!!
解决方案 »
- 请问DELPHI的工程调用过程是怎样的
- 有一段string变量,内容结构与ini文件的结构一样,有没有方便的方法读出string的内容
- 请教如何禁止一个外部进程连接80端口
- 如何将控件放置到最前面呀 谢谢
- 急 怎么利用delphi写windows API中的socket程序?
- 简单问题-如何实现IE历史栏效果,在窗口内可以点X关闭
- Webbrowser能否这样用?
- 怎么把窗体设为透明的属性?
- 大一数据结构
- 我的socketconnection老连不上application server,这是怎么回事?
- 100分请教!谁用过SoftSentry这个软件?可以给程序加上共享限制的?
- 求教:关于精确打印问题。
同时你还能学习到xml data banding 的知识。
我现在有一个这样的例子,代码如下:
unit Unit1;interface
type
IName = Interface
['{849EF1E1-EF57-11D5-8CB2-99DA2E405E0A}']
Function GetName(i: integer): String;
function GetID: string;
end;
implementationend.类的实现在下面这个单元里面
unit Unit3;interface
uses unit1;
type TMyClass = class(TInterfacedObject, IName)
private
protected
Function GetName(i: integer): String;
function GetID: string;
public
constructor create;
Destructor Destroy; override;
end;
implementation{ TMyClass }constructor TMyClass.create;
begin
end;destructor TMyClass.Destroy;
begin
inherited;end;function TMyClass.GetID: string;
begin
result := 'This is GetID test';
end;function TMyClass.GetName(i: integer): String;
begin
case i of
0:
Result := 'This is a test of GetName(0)';
1:
Result := 'This is a test of GetName(1)';
end;end;end.我在调用时用的是下面的单元,代码如下:unit Unit2;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, unit1, StdCtrls, Unit3, Buttons;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
FIName: IName;
FMyClass : TMyClass;
protected
public
end;
var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
FMyClass := TMyClass.Create;
FIName := FMYClass;
caption := FIName.GetName(1);
end;
end.这样在Button1单击时便会在窗体的标题上显示返回值,可是这样的好处是什么呢,用类完全可以实现。