delphi不同窗体的变量传递大家好,我想做一个权限控制的程序,要做的效果如下:
在form1中有用户名(nameedit.text)和密码(snedit.text),加一个登入按钮(loginbtn),在form2中有更新按钮(updatebtn)和查询(selectbtn)form1-----------当 用户名(nameedit.text)=abc -------
密码(snedit.text)=abc -------------
则form1登入成功,form1不显示,form2显示出来
-----------------form2------------
当 form1的用户名(nameedit.text)=abc时,form2的更新按钮(updatebtn)自动隐藏.
-----------------
form1源程序:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
nameedit: TEdit;
snedit: TEdit;
loginbtn: TButton;
procedure loginbtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.loginbtnClick(Sender: TObject);
begin
if (nameedit.Text='abc') and (snedit.Text='abc') then
form1.Hide;
form2.show;
end;end.
form2源程序:unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
updatebtn: TButton;
selectbtn: TButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementationuses Unit1;{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);
begin
if form1.nameedit.Text='abc' then
updatebtn.Visible:=false;end;procedure TForm2.Button1Click(Sender: TObject);
begin
if form1.nameedit.Text='abc' then
//if edit1.text='abc' then
updatebtn.Visible:=false;
end;end如form2的代码所示,应该在FormCreate时会执行updatebtn.Visible:=false,但是在form1登放成功后,form2的窗体的更新按钮(updatebtn)依然会显示.
但是如果按下Button1按钮时,更新按钮(updatebtn)却会自动隐藏.现在发现的问题是:不同窗体的变量传递时,在
procedure TForm2.FormCreate(Sender: TObject);-------执行失败
procedure TForm2.Button1Click(Sender: TObject);-----执行成功因为在程序打开时就必须要自动的云检查一下该用户是否有权限去作更新或者查询的动作,如果要每打开一个程序然后点Button1按钮检查一下是否有权限,这样的程序相信不会有人去用的。有那个有兴趣的大侠请指点一下,如果有更好的办法请把源代码一起帖上来,谢谢!
随便说一下,我用的是7.0的版本。
在form1中有用户名(nameedit.text)和密码(snedit.text),加一个登入按钮(loginbtn),在form2中有更新按钮(updatebtn)和查询(selectbtn)form1-----------当 用户名(nameedit.text)=abc -------
密码(snedit.text)=abc -------------
则form1登入成功,form1不显示,form2显示出来
-----------------form2------------
当 form1的用户名(nameedit.text)=abc时,form2的更新按钮(updatebtn)自动隐藏.
-----------------
form1源程序:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
nameedit: TEdit;
snedit: TEdit;
loginbtn: TButton;
procedure loginbtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.loginbtnClick(Sender: TObject);
begin
if (nameedit.Text='abc') and (snedit.Text='abc') then
form1.Hide;
form2.show;
end;end.
form2源程序:unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
updatebtn: TButton;
selectbtn: TButton;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementationuses Unit1;{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);
begin
if form1.nameedit.Text='abc' then
updatebtn.Visible:=false;end;procedure TForm2.Button1Click(Sender: TObject);
begin
if form1.nameedit.Text='abc' then
//if edit1.text='abc' then
updatebtn.Visible:=false;
end;end如form2的代码所示,应该在FormCreate时会执行updatebtn.Visible:=false,但是在form1登放成功后,form2的窗体的更新按钮(updatebtn)依然会显示.
但是如果按下Button1按钮时,更新按钮(updatebtn)却会自动隐藏.现在发现的问题是:不同窗体的变量传递时,在
procedure TForm2.FormCreate(Sender: TObject);-------执行失败
procedure TForm2.Button1Click(Sender: TObject);-----执行成功因为在程序打开时就必须要自动的云检查一下该用户是否有权限去作更新或者查询的动作,如果要每打开一个程序然后点Button1按钮检查一下是否有权限,这样的程序相信不会有人去用的。有那个有兴趣的大侠请指点一下,如果有更好的办法请把源代码一起帖上来,谢谢!
随便说一下,我用的是7.0的版本。
解决方案 »
- bigint类型变量 , 如果用inttohex函数操作 是不是会有错 怎么解决?
- TIdUDPServer 的 onread接收不到数据
- 请问有谁用Delphi7.0+SQL Server2000设计过“学生成绩管理系统”,我要做毕业设计
- IdTcpClient的一个问题,以前好好的,今天就出问题了,不知道为什么
- 有关messagedlg的问题!急!!!
- 如何实现在树的节点前加入类似于checkbox的可选框?
- Access数据库.QueryHelp(answer);
- 为何DELPHI中的报表不能连续打印???
- 关于线程和资源锁定的问题
- 怎样获得一个硬盘的序列号,请附详细的原代码
- 字符串操作方法问题?
- 如何在创建的子窗体中得知父窗体是哪个
with form2.create(application) do
begin
ssss := form1.aaa.text //ssss为FROM2的PUBLIC变量
showmodel; //SHOW出窗体
if modelresult = mrok then
begin
free;
end;
end;
大致是这样一个代码,我这里没有环境,否则就帮你搞定了,哎,学DELPHI的时候,看着例子学习会比较快些
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
name: string;
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
form2: Tform2;
begin
name := tRIM(EDIT1.Text);
if (Trim(edit1.Text) = 'abc') and (Trim(edit2.Text) = 'abc') then
begin
form1.Hide;
form2 := Tform2.Create(Application);
form2.show;
end;
end;end.