如何使用IAppser接口从远程数据模块或Corba数据模块返回数据集,100分献上。 (100分)

  • 主题发起人 主题发起人 oude
  • 开始时间 开始时间
O

oude

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大哥请进!
 
给你个例子
server:
procedure TRemoteServer.GetRecord_TB_JCWH_DCDW(var vtable: OleVariant);
var
// m : Integer;
nRecords, nColumns, nCurRec : Integer;
str: string;
begin
//***********查询数据库得到建树的结果集*******
str:='select dcid,dcmc from tb_jcwh_dcdw order by dcid';
query3.close;
query3.sql.Clear;
query3.sql.Add(str);
try
query3.open;
except
exit;
end;
//************************************************
nRecords := -1;
nColumns := -1;
try
{ 生成数组... }
{ 大小为 0..m-1 , m 等于行数. }
nColumns := Max(0, 1);
{ 每一元素是大小 (0..n) 的数组,n 等于记录数 }
{ 第0个元素存贮显示字段名. }
nRecords := Max(0, query3.RecordCount-1);
vtable := VarArrayCreate([0, nColumns, 0, nRecords],
varVariant);
//for m := 0 to nColumnsdo
// vtable[m, 0] := query3.Fields[m].DisplayLabel;
query3.First;
nCurRec := 0;
{ nCurRec记录当前记录号. }
while not query3.Eofdo
begin
{ 赋字段值. }
vtable[0, nCurRec] := query3.Fieldbyname('dcid').asstring;
vtable[1, nCurRec] := query3.Fieldbyname('dcmc').asstring;
query3.Next;
Inc(nCurRec);
end;
except
on E: Exceptiondo
raise Exception.Create('CreateVarArrayFromDataset() - ' +
IntToStr(nRecords) +
' rec,'+IntToStr(nColumns)
+'cols,'+E.Message);
end;
end;

client:
//**************建电厂名称框***********
procedure Tqx_xqss_main.FormCreate(Sender: TObject);
var Ldata:Tdata;
dataquery:olevariant;
j : integer;
i : integer;
begin
try
DCOMConnection1.Connected := true;
except
showmessage('数据库连接错误');
exit;
end;

//得到建树结果集
DCOMConnection1.AppServer.GetRecord_TB_JCWH_DCDW(dataquery);
if varisarray(dataquery) then
begin
i := vararrayhighbound(dataquery,2);
end
else
exit;

ldata := nil;
j := 0;
while (j <= i)do
begin
try
Ldata:=Tdata.Create;
except
exit;
end;
Ldata.dcid:=dataquery[0,j];
CbX_dcmc.Items.AddObject(dataquery[1,j],Ldata);
inc(j);
end;
if CbX_dcmc.Items.Count < 1 then
begin
FCurrentDcid:='';
exit;
end;
CbX_dcmc.ItemIndex:=0;
FCurrentDcid:=TData(CbX_dcmc.Items.Objects[CbX_dcmc.ItemIndex]).dcid;
end;
//**************************************
 
非常感谢给出如此详细的实例,我可能在贴子上表诉得不清处
我是要使用Appserver接口直接返回像TTable或TDataclint的
Data集。使得返回的变量可以直接给数据源以方便使用感应控件。
 
如果你不要用感知控件的话,那你用Tclientdataset控件不就是你要的数据集吗
不然你就用数据返回,用这些数据写Tstringgrid,我公司都是这样做的
 
function Tright_set_server.savedata(var user_id, parent_id,
right_set: OleVariant): OleVariant;
//用户权限信息保存
var
m_sql :string;
m_set :tclientdataset;
begin
try
m_set:=tclientdataset.create(self);
except
savedata:=false;
exit;
end;

m_set.data:=right_set;
rights_db.Connected:=true;
rights_db.StartTransaction ;
//删除该用户当前的权限信息
m_sql:='delete from mtxh_user_right_info where user_id='+chr(39)+trim(user_id)+chr(39);
m_sql:=m_sql+' and right_id in (select a.right_id from mtxh_user_right_info a,mtxh_right_base_info b ';
m_sql:=m_sql+' where a.user_id='+chr(39)+trim(user_id)+chr(39)+' and b.right_id=a.right_id ';
m_sql:=m_sql+' and b.parent_id='+chr(39)+trim(parent_id)+chr(39)+')';
try
server_query.Close;
server_query.SQL.Clear;
server_query.sql.add(m_sql);
server_query.ExecSQL ;
except
rights_db.Rollback;
server_query.close;
rights_db.Connected:=false;
savedata:=false;
exit;
end;

m_set.First ;
while m_set.Eof=falsedo
begin
m_sql:='insert into mtxh_user_right_info(user_id,right_id,is_have) values(';
m_sql:=m_sql+chr(39)+trim(user_id)+chr(39)+',';
m_sql:=m_sql+chr(39)+trim(m_set.fieldbyname('right_id').asstring)+chr(39)+',';
m_sql:=m_sql+chr(39)+trim(m_set.fieldbyname('is_have').asstring)+chr(39)+')';
try
server_query.Close;
server_query.SQL.Clear;
server_query.sql.add(m_sql);
server_query.ExecSQL ;
except
rights_db.Rollback;
server_query.close;
rights_db.Connected:=false;
savedata:=false;
exit;
end;
m_set.next;
end;
rights_db.Commit ;
server_query.close;
rights_db.Connected:=false;
savedata:=true;
end;
其中right_set是返回的数据集,在客户端调用
TclientDataSet.data:=right_set就可以了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部