当前位置 : 主页 > 编程语言 > delphi >

delphi 双击dbgrid 调用另一窗体的例子

来源:互联网 收集:自由互联 发布时间:2021-06-23
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls; type TForm1 = class(TForm) DataSource1: TDataSource; ADOTable1: TADOTable; DBGrid1: TDBGrid;

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    DBGrid1: TDBGrid;
    Button1: TButton;
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
   //  var
     DataSet : TDataSet


  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.DBGrid1DblClick(Sender: TObject);
//var
//DataSet : TDataSet
   begin
 DataSet := DBGrid1.DataSource.DataSet;
 with TForm2.Create(nil)  do begin
    edit1.text :=DataSet.FieldByName(‘客户‘).Asstring;
    ShowModal;
    Free;

end;
  end;
end.
连上面

 procedure TForm2.Button1Click(Sender: TObject);begin with adoquery1 dobeginclose;sql.clear;sql.add(‘select * from 销售表 where 客户=‘‘‘+trim(edit1.text)+‘‘‘‘);open;end;end;

网友评论