C
computerzzz
Unregistered / Unconfirmed
GUEST, unregistred user!
我在登陆对话框中对主对话框的属性赋值,但是在主对话框中的属性还是为空.
program Project1;
uses
Forms,
MainFrm in 'MainFrm.pas' {MainForm},
LoginFrm in 'LoginFrm.pas' {Login},
dmunit in 'dmunit.pas' {DM: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TDM, DM);
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TLogin,Login);
Login.ShowModal;
Login.Free;
Application.Run;
end.
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, TFlatButtonUnit, Menus;
type
TMainForm = class(TForm)
FlatButton1: TFlatButton;
FlatButton2: TFlatButton;
FlatButton3: TFlatButton;
FlatButton4: TFlatButton;
FlatButton5: TFlatButton;
FlatButton6: TFlatButton;
StatusBar1: TStatusBar;
FlatButton7: TFlatButton;
FlatButton8: TFlatButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
user:string;
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
var
ss:string;
begin
ss:=MainForm.user;
MainForm.StatusBar1.Panels[0].Text:='日期:'+DateToStr(Date);
MainForm.StatusBar1.Panels[1].Width:=100;
MainForm.StatusBar1.Panels[1].Text:=
'操作员:'+MainForm.user;{己经对MainForm.user赋过值了并不为空!!}
end;
end.
unit LoginFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, DB, ADODB;
type
TLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
Name: TEdit;
PWD: TEdit;
Image1: TImage;
Ok: TBitBtn;
Cancel: TBitBtn;
procedure OkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CancelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
times:integer;
end;
var
Login: TLogin;
implementation
{$R *.dfm}
uses dmunit,MainFrm;
procedure TLogin.OkClick(Sender: TObject);
var
count:integer;
begin
if times<3 then
begin
inc(times);
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('select * from ausers');
dm.ADOQuery1.SQL.Add('where User_no=:szName and Password=ass');
dm.ADOQuery1.Parameters.ParamByName('szName').Value:=Trim(Name.Text);
dm.ADOQuery1.Parameters.ParamByName('pass').Value:=PWD.Text;
dm.ADOQuery1.Open;
count:=dm.ADOQuery1.RecordCount;
if count=0 then
begin
MessageBox(self.Handle,'口令不正确',' 提示信息',MB_ICONINFORMATION);
end
else
begin
MessageBox(self.Handle,'OK','INFOR',mb_iconinformation);
MainForm.user:=Name.Text;{对MainFrom属性赋值}
MainForm.ShowModal;
dm.ADOQuery1.Close;
{MainForm.Free;}
end;{if}
end
else
begin
MessageBox(self.Handle,'输入次数己超过3次','提示信息',MB_ICONINFORMATION);
Application.Terminate;
end;{if}
dm.ADOQuery1.Close;
end;
procedure TLogin.FormCreate(Sender: TObject);
begin
times:=0;
end;
procedure TLogin.CancelClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
program Project1;
uses
Forms,
MainFrm in 'MainFrm.pas' {MainForm},
LoginFrm in 'LoginFrm.pas' {Login},
dmunit in 'dmunit.pas' {DM: TDataModule};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TDM, DM);
Application.CreateForm(TMainForm, MainForm);
Application.CreateForm(TLogin,Login);
Login.ShowModal;
Login.Free;
Application.Run;
end.
unit MainFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, TFlatButtonUnit, Menus;
type
TMainForm = class(TForm)
FlatButton1: TFlatButton;
FlatButton2: TFlatButton;
FlatButton3: TFlatButton;
FlatButton4: TFlatButton;
FlatButton5: TFlatButton;
FlatButton6: TFlatButton;
StatusBar1: TStatusBar;
FlatButton7: TFlatButton;
FlatButton8: TFlatButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
user:string;
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
var
ss:string;
begin
ss:=MainForm.user;
MainForm.StatusBar1.Panels[0].Text:='日期:'+DateToStr(Date);
MainForm.StatusBar1.Panels[1].Width:=100;
MainForm.StatusBar1.Panels[1].Text:=
'操作员:'+MainForm.user;{己经对MainForm.user赋过值了并不为空!!}
end;
end.
unit LoginFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, DB, ADODB;
type
TLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
Name: TEdit;
PWD: TEdit;
Image1: TImage;
Ok: TBitBtn;
Cancel: TBitBtn;
procedure OkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure CancelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
times:integer;
end;
var
Login: TLogin;
implementation
{$R *.dfm}
uses dmunit,MainFrm;
procedure TLogin.OkClick(Sender: TObject);
var
count:integer;
begin
if times<3 then
begin
inc(times);
dm.ADOQuery1.Close;
dm.ADOQuery1.SQL.Clear;
dm.ADOQuery1.SQL.Add('select * from ausers');
dm.ADOQuery1.SQL.Add('where User_no=:szName and Password=ass');
dm.ADOQuery1.Parameters.ParamByName('szName').Value:=Trim(Name.Text);
dm.ADOQuery1.Parameters.ParamByName('pass').Value:=PWD.Text;
dm.ADOQuery1.Open;
count:=dm.ADOQuery1.RecordCount;
if count=0 then
begin
MessageBox(self.Handle,'口令不正确',' 提示信息',MB_ICONINFORMATION);
end
else
begin
MessageBox(self.Handle,'OK','INFOR',mb_iconinformation);
MainForm.user:=Name.Text;{对MainFrom属性赋值}
MainForm.ShowModal;
dm.ADOQuery1.Close;
{MainForm.Free;}
end;{if}
end
else
begin
MessageBox(self.Handle,'输入次数己超过3次','提示信息',MB_ICONINFORMATION);
Application.Terminate;
end;{if}
dm.ADOQuery1.Close;
end;
procedure TLogin.FormCreate(Sender: TObject);
begin
times:=0;
end;
procedure TLogin.CancelClick(Sender: TObject);
begin
Application.Terminate;
end;
end.