用DELPHI創建DLL,怎麼才能讓DBGrid做為參數傳給DLL?

budwn 2006-06-15 10:08:36
我現在在DLL 定義的一個過程
Procedure Open_GroupForm(form_name:string;ado_grid:Twincontrol;ado_connts:string);stdcall;
DLL編譯沒有問題,且可以調用,但傳過來的DBGrid1跟本就沒有一點用處,(ado_grid.ClassType=Tdbgrid)=False 跟本就沒有找到,我不知道為什麼,這個DLL編譯成EXE是可以正常運行的,也就是(ado_grid.ClassType=Tdbgrid)=True
TDBGrid不知道到底可不可以作為DLL的參數
...全文
131 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxtdxvb 2006-06-15
  • 打赏
  • 举报
回复
具体联系 qq 479543842
sxtdxvb 2006-06-15
  • 打赏
  • 举报
回复
不需要那么做!

直接由dll传出 数据集变体,前台再用 ClientDataSet填充,就可以显示在 DBGrid 中了
budwn 2006-06-15
  • 打赏
  • 举报
回复
下面是我的原程序,希望各位高手們幫忙

Var ado_Z:TDBGrid;
ado_connt:Tadoconnection;
Row_data:Array of string;
col_data:Array of string; //全局變量

Procedure Open_GroupForm(form_name:PChar;ado_grid:TDBGrid;ado_connts:PChar);stdcall;
begin //在應用程序中傳過來的是DBGrid1
if not Assigned(Group_mainF) then
Group_mainF:=TGroup_mainF.Create(nil);
Group_mainF.init_dataset(form_name,ado_grid,ado_connts);
Group_mainF.Show;
end;


procedure TGroup_mainF.init_dataset(form_name:PChar;ado_Grid: TDBGrid;ado_connts:PChar);
var i:integer;
row_n,Col_n:integer; //得出ado_Grid對應的數據集用在統計中的列數據和行數據的共有數組大小
r_n,c_n:integer;
begin
ado_z:=ado_Grid;
row_n:=0; Col_n:=0;
r_n:=0; c_n:=0;
If (ado_z.ClassType=Tdbgrid) then
Begin //跟本就沒有執行裡面,也就是ado_z.ClassType<>Tdbgrid
if TDBGrid(ado_z).DataSource.DataSet is Tadodataset then
Begin
for i:=0 to Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields.Count -1 do
if Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftMemo,Ftstring,ftDate,ftDateTime] then
inc(row_n)
else if Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftSmallint,ftInteger,ftWord,ftFloat,ftBCD] then
inc(Col_n);
end
else
Begin
for i:=0 to TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields.Count -1 do
if TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftMemo,Ftstring,ftDate,ftDateTime] then
inc(row_n)
else if TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftSmallint,ftInteger,ftWord,ftFloat,ftBCD] then
inc(Col_n);
end;
end;

setLength(row_data,Row_n);
setLength(col_data,col_n);

If (ado_z.ClassType=Tdbgrid) then
Begin
if TDBGrid(ado_z).DataSource.DataSet is Tadodataset then
Begin
for i:=0 to Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields.Count -1 do
if Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftMemo,Ftstring,ftDate,ftDateTime] then
begin
Row_data[r_n]:='('+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].DisplayLabel+')['+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].FieldName+']';
inc(R_n);
end
else if Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftSmallint,ftInteger,ftWord,ftFloat,ftBCD] then
begin
Col_data[C_n]:='('+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].DisplayLabel+')['+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].FieldName+']';
inc(C_n);
end;
end
else
Begin
for i:=0 to TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields.Count -1 do
if TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftMemo,Ftstring,ftDate,ftDateTime] then
begin
Row_data[r_n]:='('+TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].DisplayLabel+')['+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].FieldName+']';
inc(R_n);
end
else if TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].datatype in[ftSmallint,ftInteger,ftWord,ftFloat,ftBCD] then
begin
Col_data[C_n]:='('+TADOQuery(TDBGrid(ado_z).DataSource.DataSet).Fields[i].DisplayLabel+')['+Tadodataset(TDBGrid(ado_z).DataSource.DataSet).Fields[i].FieldName+']';
inc(C_n);
end;
end;
end;
try
ado_connt:=Tadoconnection.Create(nil);
ado_connt.ConnectionString :=ado_connts;
ado_connt.LoginPrompt :=false;
ado_connt.Connected :=true;

name_type:=form_name;
ado_main.Connection :=ado_connt;
ado_main.SQL.Add('select * from budwn_sys_group_report where form_name='''+form_name+'''');
ado_main.open ;
except
showmessage('數據庫連接錯誤!');
end;

budwn 2006-06-15
  • 打赏
  • 举报
回复
D7的
GARNETT2183 2006-06-15
  • 打赏
  • 举报
回复
你用D7还是BDS2006?
Procedure Open_GroupForm(form_name:string;ado_grid:Twincontrol;ado_connts:string);stdcall;
在D7有没有引和ShareMM这个单元?如果没有就把form_name:string改为PChar类型传递!
在D2006里面的话,就不用了...
mdejtod 2006-06-15
  • 打赏
  • 举报
回复
帮顶一下~~~不懂~~嘿
budwn 2006-06-15
  • 打赏
  • 举报
回复
你不要判斷 ado_grid.ClassType=Tdbgrid
只要是TObject,就會發生: Sender.ClassType <> TObject

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧