我現在在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的參數

解决方案 »

  1.   

    你用D7还是BDS2006?
    Procedure Open_GroupForm(form_name:string;ado_grid:Twincontrol;ado_connts:string);stdcall;
    在D7有没有引和ShareMM这个单元?如果没有就把form_name:string改为PChar类型传递!
    在D2006里面的话,就不用了...
      

  2.   

    下面是我的原程序,希望各位高手們幫忙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;
      

  3.   

    不需要那么做!直接由dll传出 数据集变体,前台再用 ClientDataSet填充,就可以显示在 DBGrid 中了
      

  4.   

    你不要判斷 ado_grid.ClassType=Tdbgrid 
    只要是TObject,就會發生: Sender.ClassType <> TObject