公司人员表为RY001
RY0101 RY0102 RY0105
000001 超级用户 123
000002 玲玲 123
小弟在form1做了一个登录界面,用户名输入000001,000002和密码123就能登录到第二个界面form2。
现在小弟想在form2界面上的状态栏显示登录用户对应的RY0102数值,请教各位高手怎么实现???
RY0101 RY0102 RY0105
000001 超级用户 123
000002 玲玲 123
小弟在form1做了一个登录界面,用户名输入000001,000002和密码123就能登录到第二个界面form2。
现在小弟想在form2界面上的状态栏显示登录用户对应的RY0102数值,请教各位高手怎么实现???
解决方案 »
- 给版主大人提的意见!!
- 有谁有DevExpress公司的Coderush for delphi7吗?
- pb调用delphi dll的问题,delphi输出几函数给PB调用,其中一个调用返回值不行???
- 帮帮心各位大师.急啊.
- 请 myling(阿德) 朋友来接分。
- 期望您解说一下DELPHI+ORACLE的问题。
- 一个简单问题,我就是不知道?
- 整样变掉窗口标题的字体?
- 我如何把一个16进制的数串转换为2进制的树串???
- 如何为动态生成的控件(如button)生成onclick 等事件
- 线程中动态创建TImage有特殊的要求吗
- 各位大虾!SQL Server 2000数据库的问题 ,请帮忙 急!急!急!急!急!急!
如果楼主是由form2调用登陆窗体,想让登陆窗体返回值的话,可以在登陆窗体单元中添加一个公共变量或在登陆窗体public中添加一个公共属性,登陆成功后从表中取出RY0102,赋给公共变量或添加的那个属性,返回form2后,在窗体释放前取得这个变量的值就保存,或直接写道form2的状态栏里去
{----------------------------------------
登陆窗体单元
-----------------------------------------}unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;type
TForm2 = class(TForm)
Button1: TButton;
edtUserName: TEdit;
edtPassword: TEdit;
qry: TADOQuery;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FUserPower: string;
public
{ Public declarations }
property UserPower: string read FUserPower;
end;var
Form2: TForm2;implementation
uses Unit3;
{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
with qry do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM test');
Open;
end;
if qry.Locate('RY0101;RY0105', VarArrayOf([edtUserName.Text, edtPassword.Text]), []) then
begin
FUserPower := qry.FieldByName('RY0102').AsString;
Form3.Show;
end
else begin
//自己加出错处理
end;
end;end.
{---------------------------------------------------
要显示RY0102的单元
----------------------------------------------------}
unit Unit3;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TForm3 = class(TForm)
StatusBar1: TStatusBar;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form3: TForm3;implementation
uses Unit2;
{$R *.dfm}procedure TForm3.FormShow(Sender: TObject);
begin
StatusBar1.Panels[0].Text := Form2.UserPower;
end;end.
var
S : string;
begin
S := 'select * from RY001 where RY0101 ='+ QuotedStr(Edit1.Text)
+ ' and RY0105 ='+QuotedStr(Edit2.Text);
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(S);
Open;
end;
if ADOQuery1.RecordCount <> 0 then
begin
Form2.Show;
Form2.StatusBar1.Panels[0].Text := ADOQuery1.FieldByName('RY0102').AsString;
end
else
begin
//做出其他判断,是否用户名、密码错误等
end;
end;前提:要双击StatusBar1,为其添加Panels,否则会报错。不知这样是否满意。一起学习……
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBTables;type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Image1: TImage;
Query1: TQuery;
DataSource1: TDataSource;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
ScreenWidth=1024;
ScreenHeight=768;var
Form2: TForm2;implementation
uses Unit1;{$R *.dfm}procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
parambyname('mc').AsString:=Edit1.Text;
parambyname('mm').AsString:=Edit2.Text;
open;
end;
if query1.recordcount<>0 then
begin
form1.Show;
form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;
end
else
begin
application.MessageBox('您的用户名或密码不正确,请重新输入!','提示',mb_ok);
edit1.SetFocus;
abort;
end;
end;
procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
edit2.SetFocus;
end;procedure TForm2.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
Button1.SetFocus;
end;procedure TForm2.FormShow(Sender: TObject);
begin
edit1.SetFocus;
end;procedure TForm2.FormCreate(Sender: TObject);
begin
inherited;
Font.Name := '宋体';
Font.Size := 9;
Scaled := True;
if (screen.Width<>ScreenWidth) then
begin
Height := LongInt(height)*longInt(Screen.height)div ScreenHeight;
Width := LongInt(Width)*LongInt(screen.width)div ScreenWidth;
ScaleBy(Screen.width,ScreenWidth);
end;
end;
end.
-----------------------------------------------------------------------------
上面是我写的,在这里我还有个问题,就是form2怎么在登陆后关闭,我在
form1.StatusBar1.Panels[1].Text :=query1.FieldByName('RY0102').AsString;后加个form2.close;怎么连form1都不能显示了!!!