现在有两个窗体form1、form2,要实现根据form1中edit1的字段值,在form2中自动显示user_pswd、user_dgr两个值
form1中
    edit1    user_nm
    edit2    user_pswd
    edit3    user_dgr
对应到数据库form2中
    edit1    user_pswd
    edit2    user_dgrunit2代码如下
unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);
begin
  with Form1.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select * from Users where user_nm =:a');
    Parameters.ParamByName('a').Value := Trim(Form1.Edit1.Text);
    Open;
  end;
  begin
    Edit1.Text :=Form1.ADOQuery1.FieldByName('user_pswd').Value;
    Edit2.Text :=Form1.ADOQuery1.FieldByName('user_dgr').Value;
  end;
end;end.

解决方案 »

  1.   

    补充一下,数据库连接没有问题,现在遇到这个问题  Edit1.Text :=Form1.ADOQuery1.FieldByName('user_pswd').Value;
      Edit2.Text :=Form1.ADOQuery1.FieldByName('user_dgr').Value;这么写不知道哪里错了呢,各位来帮帮小弟,不胜感激!
      

  2.   

    Edit1.Text :=Form1.ADOQuery1.FieldByName('user_pswd').Asstring; Edit2.Text :=Form1.ADOQuery1.FieldByName('user_dgr').Asstring;
      

  3.   

      不要些到Create事件中,写到Form2的show事件里面
      
      procedure TForm2.FormShow(Sender: TObject);    //这里
    begin
      with Form1.ADOQuery1 do
      begin
      Close;
      SQL.Clear;
      SQL.Add('Select * from Users where user_nm =:a');
      Parameters.ParamByName('a').Value := Trim(Form1.Edit1.Text);
      Open;
      end;
      begin
      Edit1.Text :=Form1.ADOQuery1.FieldByName('user_pswd').AsString;
      Edit2.Text :=Form1.ADOQuery1.FieldByName('user_dgr').AsString;
      end;
    end
      
      

  4.   

    你可以这样实现,
    Form1.ADOQuery1 在form1窗体中执行,在Form2 中建立两个全局变量,
    在Form1 窗体中调用Form2 窗体时,将查询去的查询传给Form2 中的变量,然后你再相关的处理即可。
      

  5.   

    最好别用全局变量 用属性property ……