form1的参数怎么传给form2?
比如一个登陆界面,输入用户名,密码。通过验证后,出现一个主操作窗口,这个窗口怎么接受那个登陆界面输入的用户名和密码?我想判断这个用户的权限?

解决方案 »

  1.   

    1.直接将户名,密码设为public属性,在form2中uses form1
     然后
        username1:=form1.username;
      ...
    2.在form1中写一过程,
      procedure getlogin(var username,password:string);
     然后在form2中调用它,并将值取回
      

  2.   

    你的程序里应该有data module 的吧,假设名称为dm 。在data module 上定义两个变量
    var
    vuser,vpasswd:string;在登陆窗体上uses dm 
    然后给变量赋值
    vuser:=Trim(edit1.text);////////假设edit1是输入拥护名的
    vpasswd:=Trim(edit2.text);////////假设edit2是输入密码的在主窗体上uses dm 然后调用vuser,vpassword就可得到这两个值了
    比如想用它做参数来查询权限表就可以这样写sql语句(假设表名为table1 ,拥护名字段 为user_id  )select * from table1 where user_id ='''+vuser+'''
      

  3.   

    我是些一个函数调用form2
    ,然后传递参数,参数可以
    public 在form2,如果懒了
    也可以不定义
    直接付给hint,用完了就nil,
    也还可以。
      

  4.   

    在form2定义全局变量:
    在Form1中uses form2,就可以直接调用。
      

  5.   

    使用use 语句假设你的form2的单元叫unit2,那么你可以在form1里面这样写:use unit2unit2.form2.*    /*代表对象名
      

  6.   

    在主窗口的public部分定义全局变量,并在子窗口的单元文件uses主窗口单元文件即可操作主窗口类的public部分的变量了.
      

  7.   

    在from1中设置要传递的参数为全局变量,然后在from2中引用就行了。例格式为from1.button
      

  8.   

    首先窗体也是对象。也就是对象A如果访问对象B每个对象提供属性published给别人访问,提供方法public给别人提供服务。对象的数据要放在private 中保护。不要放在Public中。全局变量在这里没有必要使用。
      

  9.   

    一个例子。共有四个文件
    -----------------------------------
    文件一:ProTest.dpr 工程文件
    program ProTest;
    uses
      Forms,
      WinLogon in 'WinLogon.pas' {frm_Logon},
      WinMain in 'WinMain.pas' {frm_Main},
      LogonClass in 'LogonClass.pas';{$R *.res}
    var
      FLogon_Obj:TLogon_Obj;
    begin
      Application.Initialize;
      FLogon_Obj:=TLogon_Obj .Create ;
      FLogon_Obj.Logon :=True;
      if FLogon_Obj.Logon then
      begin
        Application.CreateForm(Tfrm_Main, frm_Main);
        frm_Main.UserName :=FLogon_Obj .UserName;
      end;
      FLogon_Obj.Free;
      FLogon_Obj:=Nil;
      Application.Run;
    end.
    -----------------------------
    文件2 登陆窗体 WinLogon.pas
    interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;Const
      CO_ERRSTR_LONON='用户名或密码不正确。请重新输入。密码的字母必须使用正确的大小写。请确定是否因疏忽而按下了 Caps Lock。';
    type  TOnValidateUserEvent=function (AUserName,APassWord:String):Boolean Of Object;  Tfrm_Logon = class(TForm)
        btn_Ok: TButton;
        btn_Cancel: TButton;
        edt_UserName: TLabeledEdit;
        edt_PassWord: TLabeledEdit;
        Bevel1: TBevel;
        procedure FormCreate(Sender: TObject);
        procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
      private
        FValidateCount:Integer;
        FOnValidateUserEvent: TOnValidateUserEvent;
        procedure SetUserName(const Value: String);
        function GetUserName: String;
        { Private declarations }
      public
        { Public declarations }
      published
        property UserName:String Read GetUserName Write SetUserName;
        property OnValidateUser:TOnValidateUserEvent Read FOnValidateUserEvent Write FOnValidateUserEvent;
      end;implementation{$R *.dfm}{ Tfrm_Logon }function Tfrm_Logon.GetUserName: String;
    begin
      Result:=Trim(edt_UserName.Text);
    end;procedure Tfrm_Logon.SetUserName(const Value: String);
    begin
      edt_UserName.Text := Value;
    end;procedure Tfrm_Logon.FormCreate(Sender: TObject);
    begin
      edt_UserName .Clear;
      edt_PassWord .Clear;
      FValidateCount:=0;
    end;procedure Tfrm_Logon.FormCloseQuery(Sender: TObject;
      var CanClose: Boolean);
    begin
      if ModalResult =mrOk then
        if Assigned(OnValidateUser) then
          if False=OnValidateUser(edt_UserName.Text,edt_PassWord .Text ) then
          begin
            if 2>FValidateCount then
            begin
              inc(FValidateCount);
              CanClose:=False;
              Application .MessageBox(CO_ERRSTR_LONON,PChar(Caption),MB_OK+MB_ICONEXCLAMATION);
              edt_UserName.SetFocus ;
            end
            else
              ModalResult :=mrCancel;
          end;
    end;end.
    ------------------------------------------
    文件3 主窗体 WinMain.pas
    unit WinMain;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      Tfrm_Main = class(TForm)
      private
        FUserName: String;
        procedure SetUserName(const Value: String);
        { Private declarations }
      public
        { Public declarations }
      published
        property UserName:String Read FUserName Write SetUserName;
      end;var
      frm_Main: Tfrm_Main;implementation{$R *.dfm}{ Tfrm_Main }procedure Tfrm_Main.SetUserName(const Value: String);
    begin
      FUserName := Value;
      Caption:=Value;
    end;end.
    ----------------------------------
    文件四:登陆类 LogonClass.pasunit LogonClass;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;Type
      TLogon_Obj=Class
      private
        FLogon: Boolean;
        FUserName: String;
        procedure SetLogon(const Value: Boolean);
      protected
        function ValidateUser(AUserName,APassWord:String):Boolean;
      public
      published
        property Logon:Boolean Read FLogon Write SetLogon;
        property UserName:String Read FUserName;
      end;
    implementationuses WinLogon;{ TLogon_Obj }procedure TLogon_Obj.SetLogon(const Value: Boolean);
    var
      frm_Logon: Tfrm_Logon;
    begin
      if FLogon=Value then
        Exit;
      if Value then
      begin
        frm_Logon:=Tfrm_Logon.Create(Application);
        frm_Logon.UserName :=FUserName ;
        frm_Logon.OnValidateUser :=ValidateUser;
        frm_Logon.ShowModal ;
        if mrOk=frm_Logon.ModalResult then
        begin
          FUserName :=frm_Logon.UserName;
          FLogon := Value;
        end;
        FreeAndNil(frm_Logon);
      end
      else
      begin
        FUserName :='';
        FLogon := Value;
      end;
    end;function TLogon_Obj.ValidateUser(AUserName, APassWord: String): Boolean;
    begin
      Result:=False;
      if (AUserName='CADN')and(APassWord='XYZ') then
        Result:=True;
    end;end.
      

  10.   

    两个窗体
    ------------------------------
    主窗体 WinMain.dfmobject frm_Main: Tfrm_Main
      Left = 263
      Top = 234
      Width = 422
      Height = 281
      Caption = '主窗体'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      Position = poScreenCenter
      PixelsPerInch = 96
      TextHeight = 13
    end--------------------------------
    登陆窗体 WinLogon.dfmobject frm_Logon: Tfrm_Logon
      Left = 369
      Top = 313
      BorderStyle = bsDialog
      Caption = '登陆'
      ClientHeight = 109
      ClientWidth = 278
      Color = clBtnFace
      Font.Charset = ANSI_CHARSET
      Font.Color = clWindowText
      Font.Height = -12
      Font.Name = '宋体'
      Font.Style = []
      OldCreateOrder = False
      Position = poScreenCenter
      OnCloseQuery = FormCloseQuery
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 12
      object Bevel1: TBevel
        Left = 8
        Top = 72
        Width = 265
        Height = 10
        Shape = bsTopLine
      end
      object btn_Ok: TButton
        Left = 112
        Top = 80
        Width = 75
        Height = 22
        Caption = '确定'
        Default = True
        ModalResult = 1
        TabOrder = 2
      end
      object btn_Cancel: TButton
        Left = 192
        Top = 80
        Width = 75
        Height = 22
        Cancel = True
        Caption = '取消'
        ModalResult = 2
        TabOrder = 3
      end
      object edt_UserName: TLabeledEdit
        Left = 80
        Top = 8
        Width = 185
        Height = 20
        EditLabel.Width = 60
        EditLabel.Height = 12
        EditLabel.Caption = '用户名(&U):'
        LabelPosition = lpLeft
        TabOrder = 0
      end
      object edt_PassWord: TLabeledEdit
        Left = 80
        Top = 32
        Width = 185
        Height = 20
        EditLabel.Width = 48
        EditLabel.Height = 12
        EditLabel.Caption = '密码(&P):'
        LabelPosition = lpLeft
        TabOrder = 1
      end
    end--------------------------------------
    建立七个文本文件后分别代码拷入就可以了。
      

  11.   

    这也成问题了,没学过Delphi吧
      

  12.   

    首先引用form1这个单元
    1.属性
    2.public部分变量
    3.public部分的函数
    4.protected部分,就需要继承form1中的类,然后通过这个类的实例进行访问,当然,上面1,2,3在这种情况下也可以
    5.全局变量。