但是TComponent并不存在于利用com制作向导使用的类型库中,在接口函数中,提供的数据类型并没有Tobject,
我试了一下,如果不利用向导在可以直接调用。实例代码如下:
unit transdatatype;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Db, ADODB,
StdCtrls, OleServer, xfSystemReg_TLB, Grids, DBGrids;
type
TForm1 = class(TForm)
Button1: TButton;
ADOQuery1: TADOQuery;
SystemReg1: TSystemReg;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Imyinterface=interface
procedure draw(xx:Tadoquery;str:string);
end;
Tmyclass=class(TInterfacedobject,Imyinterface)
procedure draw(xx:Tadoquery;str:string);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Tmyclass.draw(xx:Tadoquery;str:string);
begin
with xx do
begin
close;
SQL.Clear;
SQL.Add(str);
open;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ww:Imyinterface;
tempstr:string;
begin
ww:=Tmyclass.Create;
Adoquery1.ConnectionString:=SystemReg1.GetDBLoginString;
tempstr:='select * from geobookmark';
ww.draw(adoquery1,tempstr);
end;
end.
注意, xfSystemReg_TLB是通过注册标连接数据库的一个com