Dbcombox1的数据是中文字'查找'时,
if Table1.Active<>True then
Table1.Active:=True;
frmgetdata.init;
frmgetdata.mydatasource:=dm.DS_Table1;
if Frmgetdata.show then
begin
E_DptNo.Text:=Frmgetdata.getvalue('dptno');
EdptNo.Text:=Frmgetdata.getvalue('dptno');
end;
下面是另一unit 代码
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);
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;
你的问题参考上面应能解决。