delphi中分布系统的问题(客户端)(100分)

  • 主题发起人 主题发起人 ljq_2002
  • 开始时间 开始时间
L

ljq_2002

Unregistered / Unconfirmed
GUEST, unregistred user!
有如下的一个函数:
GetAllTables(var param1: OleVariant);
var
tbllist:Tstringlist;
...
begin
tbllist:= TstringList.create;
....
param1 := VarArrayCreate([0,tbllist.Count-1],varVariant);
....
end;

目的是能从SQL server服务器中得到表,在编译时出现如下的错误:
[Error] Unit2.pas(52): Undeclared identifier: 'VarArrayCreate'
求各位高手帮忙??
 
ues Variants
 
是不是 uses 里没加variants?
 
在DELPHI 5里是可以运行的,但在D6里要加uses variants
 
你查查VarArrayCreate在哪个里面,就知道了该加什么了(使用Ctrl+Mouse点击一下就知道了)
 
这是李维那本术中的,程序测试代码如下,供参考:(在D6下通过)
---------
unit Unit2;
{$WARN SYMBOL_PLATFORM OFF}
interface

uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Project1_TLB, StdVcl, Provider, DB, ADODB,Variants;

type
Tserver_x = class(TRemoteDataModule, Iserver_x)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DataSetProvider1: TDataSetProvider;
procedure DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
procedure DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
function DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
private
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
procedure GetAllTables(var vTables: OleVariant); safecall;
public
{ Public declarations }
end;
implementation
uses Unit1;
{$R *.DFM}
class procedure Tserver_x.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;

procedure Tserver_x.GetAllTables(var vTables: OleVariant);
var //-----------------这是你的程序的地方--------------------
tbList:TstringList;
iCount:integer;
begin
try
tbList:=TstringList.Create;
ADOConnection1.GetTableNames(tbList);
vTables:=VarArrayCreate([0,tbList.count-1],varVariant);
for icount:=0 to tbList.Count-1 do
begin
vTables[iCount]:=tbList.Strings[icount];
end;
finally
tbList.Free;
end;
end;

procedure Tserver_x.DataSetProvider1GetData(Sender: TObject;
DataSet: TCustomClientDataSet);
begin
if form1.label1.caption='EDUCAST_SERVER' then
form1.label1.caption:='SERVER'
else form1.label1.caption:='EDUCAST_SERVER';
end;

procedure Tserver_x.DataSetProvider1AfterGetRecords(Sender: TObject;
var OwnerData: OleVariant);
begin
if form1.label1.caption='EDUCAST_SERVER' then
form1.label2.Caption:='EDUCAST_SERVER';
if form1.label1.caption='SERVER' then
form1.label2.caption:='SERVER' ;
end;

function Tserver_x.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
var iRecords:integer;
begin
{ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(input);
ADOQuery1.Open; }
form1.label3.caption:=input ;
// Result:= DataSetProvider1.GetRecords(0,0,0);
//DataSetProvider1.reset(true);
//Result:=DataSetProvider1.GetRecords( 10,iRecords);;
//:=DataSetProvider1.GetRecords( 10,10);
end;

initialization
TComponentFactory.Create(ComServer, Tserver_x,
Class_server_x, ciMultiInstance, tmApartment);
end.
 

Similar threads

后退
顶部