用系统变量APPLICATION可以解决的!

解决方案 »

  1.   

    if (ActiveControl is TDBGrid) then
    if TDBGrid(ActiveControl)=
    通过TDBGrid(ActiveControl)可以取得当前的dbgrid
      

  2.   

    指向同一个点击事件
    TDBGrid(Sender).Name
      

  3.   

    我是定义了这样一个过程
    PROCEDURE WP_FY(DBG:TDbgrid);
    调用时如何自动读取当前dbgrid的名字
    wp_fy();//这里要如何写?
      

  4.   

    function wp_fy(DBG: TDBGrid): string;
    begin
      Result := DBG.Name;
    end;//orprocedure wp_fy(DBG: TDBGrid);
    begin
      {用DBG.Name};
    end;
      

  5.   

    三个grid共用同一click事件:
    (Sender as TDbGrid).Name可取回当前grid的name
      

  6.   

    这样也不行比如 有三个DBGRID都要做同样的事件,且事件内容相同,这样要如何写
    procedure TOU_FOR.DBGrid1ColExit(Sender: TObject);
    begin
      if DBGrid1.SelectedField.Name='LS_SJ_TB1XJ'  then //(这里需要改为DBGRID1、2、3)
      ....
    end;
      

  7.   

    在DBGrid的事件里写
    名称 =(Sender as TDBGrid).Name
    If (Sender as TDBGrid).SelectedField.Name = 'LS_SJ_TB1XJ'  then
    就行了
      

  8.   

    //先确定当前的激活的是否为dbgrid,然后调用函数
    if (ActiveControl is TDBGrid) then wp_fy(TDBGrid(ActiveControl))
      

  9.   

    //pas
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids;type
      TForm1 = class(TForm)
        DataSource1: TDataSource;
        DBGrid1: TDBGrid;
        DataSource2: TDataSource;
        DataSource3: TDataSource;
        DBGrid2: TDBGrid;
        DBGrid3: TDBGrid;
        Table1: TTable;
        procedure Button1Click(Sender: TObject);
        procedure DBGrid1ColExit(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      Caption := Format('%-.5d', [1]); 
    end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
    begin
      ShowMessage(TDBGrid(Sender).SelectedField.FieldName);
                                              //~~~~~~~~~
    end;end.//dfm
    object Form1: TForm1
      Left = 192
      Top = 107
      Width = 544
      Height = 375
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object DBGrid1: TDBGrid
        Left = 0
        Top = 8
        Width = 177
        Height = 193
        DataSource = DataSource1
        TabOrder = 0
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'MS Sans Serif'
        TitleFont.Style = []
        OnColExit = DBGrid1ColExit
      end
      object DBGrid2: TDBGrid
        Left = 176
        Top = 8
        Width = 177
        Height = 193
        DataSource = DataSource1
        TabOrder = 1
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'MS Sans Serif'
        TitleFont.Style = []
        OnColExit = DBGrid1ColExit
      end
      object DBGrid3: TDBGrid
        Left = 352
        Top = 8
        Width = 177
        Height = 193
        DataSource = DataSource1
        TabOrder = 2
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'MS Sans Serif'
        TitleFont.Style = []
        OnColExit = DBGrid1ColExit
      end
      object DataSource1: TDataSource
        DataSet = Table1
        Left = 8
        Top = 24
      end
      object DataSource2: TDataSource
        DataSet = Table1
        Left = 200
        Top = 24
      end
      object DataSource3: TDataSource
        DataSet = Table1
        Left = 384
        Top = 24
      end
      object Table1: TTable
        Active = True
        DatabaseName = 'DBDEMOS'
        TableName = 'animals.dbf'
        Left = 232
        Top = 248
      end
    end
      

  10.   

    //先确定当前的激活的是否为dbgrid,然后调用函数
    if (ActiveControl is TDBGrid) then wp_fy(TDBGrid(ActiveControl))
    //TDBGrid(ActiveControl)为dbgrid1、2、3,传入了要处理的dbgrid
    //然后在wp_fy过程中处理
    if DBG=Dbgrid1 then...
      else if DBG=Dbgrid2 then...
        else...