我有一公用查询程序,可能符合要求。
object FrmGetData: TFrmGetData
Left = 189
Top = 109
Width = 376
Height = 309
Caption = '资料查询'
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'System'
Font.Style = [fsBold]
Position = poScreenCenter
OnActivate = FormActivate
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 16
object Panel1: TPanel
Left = 0
Top = 0
Width = 368
Height = 33
Align = alTop
TabOrder = 0
object DBNavigator1: TDBNavigator
Left = 1
Top = 1
Width = 366
Height = 31
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
Align = alClient
TabOrder = 0
end
end
object Panel2: TPanel
Left = 0
Top = 241
Width = 368
Height = 41
Align = alBottom
TabOrder = 1
object CmdOk: TButton
Left = 56
Top = 8
Width = 75
Height = 25
Caption = '&O 确定'
TabOrder = 0
OnClick = CmdOkClick
end
object CmdCancel: TButton
Left = 238
Top = 8
Width = 75
Height = 25
Caption = '&C 取消'
TabOrder = 1
OnClick = CmdCancelClick
end
end
object Panel3: TPanel
Left = 0
Top = 33
Width = 368
Height = 208
Align = alClient
TabOrder = 2
object DBGrid1: TDBGrid
Left = 1
Top = 1
Width = 366
Height = 206
Align = alClient
TabOrder = 0
TitleFont.Charset = GB2312_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -16
TitleFont.Name = 'System'
TitleFont.Style = [fsBold]
OnDblClick = DBGrid1DblClick
end
end
end
unit GetData;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DBCtrls, ExtCtrls, Grids, DBGrids, Db, DBTables;
type
TFrmGetData = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
DBNavigator1: TDBNavigator;
CmdOk: TButton;
CmdCancel: TButton;
DBGrid1: TDBGrid;
procedure FormActivate(Sender: TObject);
procedure CmdOkClick(Sender: TObject);
procedure CmdCancelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure DBGrid1DblClick(Sender: TObject);
private
DS:TDatasource;
public
property mydatasource:TDatasource read Ds write ds;
function show:boolean;
function getvalue(fname: string):variant;
procedure init;
end;
var
FrmGetData: TFrmGetData;
okornot:boolean;
implementation
{$R *.DFM}
procedure TFrmGetData.FormActivate(Sender: TObject);
begin
dbgrid1.DataSource:=mydatasource;
dbnavigator1.DataSource:=mydatasource;
end;
procedure TFrmGetData.CmdOkClick(Sender: TObject);
begin
okornot:=true;
close;
end;
procedure TFrmGetData.CmdCancelClick(Sender: TObject);
begin
okornot:=false;
close;
end;
function Tfrmgetdata.show:boolean;
begin
showmodal;
result:=okornot;
end;
function Tfrmgetdata.getvalue(fname: string):variant;
var i:integer;
begin
with mydatasource.DataSet do
begin
for i := 0 to fieldcount - 1 do
if uppercase(fields.fieldname)=
uppercase(fname)
then
result:=fields.value;
end;
end;
procedure Tfrmgetdata.init;
begin
application.CreateForm(Tfrmgetdata, frmgetdata);
end;
procedure TFrmGetData.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TFrmGetData.DBGrid1DblClick(Sender: TObject);
begin
okornot:=true;
close;
end;
end.
调用:
procedure TFDeSalary.E_dptNoDblClick(Sender: TObject);
begin
Query1.Open;// Query1<--DateSoure1
frmgetdata.init;
frmgetdata.mydatasource:=DateSoure1;
if Frmgetdata.show then
E_dptNo.Text:=Frmgetdata.getvalue('dptNo');
end;
// Query1: select * from tablename where fieldname like %+edit1.text
//fieldname 需是 char 型。