各位说的,相信都是成功之后的经验之谈。但不知怎么搞的,在下这个仍然出错。其中有个
数据模块,登录窗体中要从数据库中取出用户名,所以可能要先建立数据模块窗体。另外还有
闪现窗体。
下面是源码:
//工程文件
program rlglnew;
uses
Forms,
Messages,
Windows,
Main in 'Main.pas' {frm_Main},
skin in 'skin.pas' {frm_skin},
login in 'login.pas' {frm_login},
DataModal in 'DataModal.pas' {DM: TDataModule};
{$R *.RES}
begin
Frm_skin:=Tfrm_skin.Create(Application);
Frm_skin.Show;
Frm_skin.Update;
Application.Initialize;
Application.ShowMainForm:=False;
Application.CreateForm(Tfrm_Main, frm_Main);
Application.CreateForm(TDM, DM);
Frm_skin.free;
frm_login:=Tfrm_login.Create(Application);
frm_login.Showmodal;//运行到这个地方提示错误:connot make a visible window modal
if frm_login.ModalResult <>2 then
begin
Application.Run;
end;
end.
//登录窗体
unit login;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons;
type
Tfrm_login = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
edt_Pass: TEdit;
comb_User: TComboBox;
btn_login: TBitBtn;
btn_exit: TBitBtn;
procedure btn_exitClick(Sender: TObject);
procedure btn_logonClick(Sender: TObject);
procedure AppException(Sender: TObject; E: Exception);
procedure edt_PassClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
username:string;
unitname:string;
password:string;
oper_object:string;
end;
var
frm_login: Tfrm_login;
implementation
uses DataModal;
{$R *.DFM}
procedure Tfrm_login.btn_exitClick(Sender: TObject);
begin
close;
end;
procedure Tfrm_login.btn_logonClick(Sender: TObject);
var
Oldcursor:TCursor;
begin
if comb_User.text='SUPER' then
begin
if trim(edt_Pass.text)='888888' then
begin
username:='SUPER';
ModalResult:=mrOk;
end
else
begin
Application.MessageBox('密码错误!','提示',MB_OK+MB_ICONWARNING);
edt_Pass.SetFocus;
end;
end
else
begin
DM.Qry_User.Close;
with DM.Qry_User do
begin
SQL.Clear;
SQL.Add('select * from User_Info where UserName=:UserName');
Parameters.ParamValues['UserName']:=comb_User.Text;
end;
Application.OnException :=AppException;
DM.Qry_User.Open;
if DM.Qry_User.Eof then
begin
Showmessage('这个用户已经改变,请与系统管理员联系!');
end
else
begin
if trim(DM.Qry_User.FieldByName('password').AsString)=trim(edt_Pass.Text) then
begin
username:=DM.Qry_User.FieldByName('username').AsString;
unitname:=DM.Qry_User.FieldByName('unitname').AsString;
password:=DM.Qry_User.FieldByName('password').AsString;
oper_object:=DM.Qry_User.FieldByName('object').AsString;
ModalResult:=mrOk;
end
else
begin
Application.MessageBox('密码错误!','提示',MB_OK+MB_ICONWARNING);
edt_Pass.SelectAll;
edt_Pass.SetFocus;
end;
end;
end;
end;
procedure Tfrm_login.AppException(Sender: TObject; E: Exception);
begin
Application.ShowException(E);
Application.MessageBox('错误:数据库读取失败.'+#13+'建议您检查网络的连接情况或者与数据库系统管理员联系!',
'连接错误',MB_OK+MB_ICONWARNING);
Application.Terminate;
end;
procedure Tfrm_login.edt_PassClick(Sender: TObject);
begin
edt_Pass.SelStart :=0;
edt_Pass.SelLength :=length(edt_Pass.Text);
end;
procedure Tfrm_login.FormCreate(Sender: TObject);
begin
//try
Application.OnException :=AppException;
comb_User.Items.Clear;
DM.Tbl_User.Open;
with DM.Tbl_User do
begin
if Eof then
begin
comb_User.Items.Add('SUPER');
end
else
begin
while not DM.Tbl_User.Eof do
begin
comb_User.Items.Add(DM.Tbl_User.FieldByName('UserName').AsString);
DM.Tbl_User.Next;
end;
end;
comb_User.ItemIndex :=0;
end;
// except
// Application.MessageBox('一般网络故障,请与系统管理员联系!','提示',MB_OK);
// end;
end;
end.
//数据模块
unit DataModal;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB;
type
TDM = class(TDataModule)
ADOConnection1: TADOConnection;
Tbl_User: TADOTable;
Qry_User: TADOQuery;
Qry_BaseTable: TADOQuery;
Qry_BaseTable1: TADOQuery;
Qry_Unit: TADOQuery;
Qry_Department: TADOQuery;
Qry_Unit1: TADOQuery;
Qry_Department1: TADOQuery;
Qry_JiBen1: TADOQuery;
Qry_DanWeiBD1: TADOQuery;
Qry_BuMenBD1: TADOQuery;
Qry_User_Oper: TADOQuery;
Qry_User1: TADOQuery;
Qry_User_Oper1: TADOQuery;
Qry_NewChaXun: TADOQuery;
Qry_NewChaXunDSDesigner: TStringField;
Qry_NewChaXunDSDesigner2: TStringField;
Qry_NewChaXunDSDesigner3: TStringField;
Qry_NewChaXunDSDesigner4: TStringField;
Qry_NewChaXunDSDesigner5: TDateTimeField;
Qry_NewChaXunDSDesigner6: TStringField;
Qry_NewChaXunDSDesigner7: TStringField;
Qry_NewChaXunDSDesigner8: TWideStringField;
Qry_NewChaXunDSDesigner9: TStringField;
Qry_NewChaXunDSDesigner10: TDateTimeField;
Qry_NewChaXunDSDesigner11: TStringField;
Qry_NewChaXunDSDesigner12: TStringField;
Qry_NewChaXunDSDesigner13: TWideStringField;
Qry_NewChaXunDSDesigner14: TWideStringField;
Qry_NewChaXunDSDesigner15: TStringField;
Qry_NewChaXunDSDesigner16: TWideStringField;
Qry_NewChaXunDSDesigner17: TDateTimeField;
Qry_NewChaXunDSDesigner18: TStringField;
Qry_NewChaXunDSDesigner19: TDateTimeField;
Qry_NewChaXunDSDesigner20: TStringField;
Qry_NewChaXunDSDesigner21: TStringField;
Qry_NewChaXunDSDesigner22: TStringField;
Qry_NewChaXunDSDesigner23: TStringField;
Qry_NewChaXunDSDesigner24: TStringField;
Qry_NewChaXunDSDesigner25: TStringField;
Qry_NewChaXunDSDesigner26: TDateTimeField;
Qry_NewChaXunDSDesigner27: TStringField;
Qry_NewChaXunDSDesigner28: TStringField;
Qry_NewChaXunDSDesigner29: TStringField;
Qry_NewChaXunDSDesigner30: TDateTimeField;
Qry_NewChaXunDSDesigner31: TBlobField;
Qry_NewChaXunDSDesigner32: TStringField;
Qry_NewChaXunField: TIntegerField;
Qry_JiBen: TADOQuery;
Qry_JiBen_Print: TADOQuery;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
procedure AppException(Sender: TObject; E: Exception);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DM: TDM;
implementation
{$R *.DFM}
procedure TDM.AppException(Sender: TObject; E: Exception);
begin
//Application.ShowException(E);
Application.MessageBox('错误:数据库读取失败.'+#13+'建议您检查网络的连接情况或者与数据库系统管理员联系!',
'连接错误',MB_OK+MB_ICONWARNING);
Application.Terminate;
end;
procedure TDM.DataModuleCreate(Sender: TObject);
{var
CurTime:LongWord;
DelayTime:LongWord;}
begin
{ DelayTime:=5000;
CurTime:=GetTickCount;
while(GetTickCount<(CurTime+DelayTime)) do
begin
end; }
Application.OnException := AppException;
// ADOConnection1.Connected:=True;
//Tbl_User.Active :=True;
//Application.OnException :=nil;
end;
procedure TDM.DataModuleDestroy(Sender: TObject);
begin
ADOConnection1.Connected:=False;
ADOConnection1.KeepConnection :=False;
end;
end.
//主窗体
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, jpeg, ExtCtrls, ImgList, ComCtrls, ToolWin, StdCtrls, Buttons,
ExtDlgs, IniFiles, Db, ADODB, MDIWallp;
const
CM_RESTORE=WM_USER+$1000;
APPNAME='人力资源管理系统';
type
Tfrm_Main = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N9: TMenuItem;
LR_JIBENXX: TMenuItem;
LR_LVLIXX: TMenuItem;
LR_XUELIXX: TMenuItem;
LR_SHEHUIXX: TMenuItem;
N10: TMenuItem;
LR_ZHICHENGXX: TMenuItem;
LR_JIANGLIXX: TMenuItem;
LR_CHENGCHUXX: TMenuItem;
LR_JIANZHIXX: TMenuItem;
LR_CHUGUOXX: TMenuItem;
LR_SHANGBXX: TMenuItem;
LR_LONGDXX: TMenuItem;
BD_ZhiWu: TMenuItem;
BD_BuMen: TMenuItem;
BD_GangWei: TMenuItem;
N11: TMenuItem;
BD_ShiYong: TMenuItem;
BD_ZaiZhi: TMenuItem;
BD_LiChang: TMenuItem;
N12: TMenuItem;
BD_XIEYI: TMenuItem;
BD_ZHAOPIN: TMenuItem;
BD_FUYUANBING: TMenuItem;
XT_DANWEI: TMenuItem;
XT_BUMEN: TMenuItem;
XT_GANGWEI: TMenuItem;
XT_GWLEIBIE: TMenuItem;
XT_GWMINGCHENG: TMenuItem;
XT_GWIZHUANGTAI: TMenuItem;
XT_YONGHU: TMenuItem;
BZ_ZHUTI: TMenuItem;
N14: TMenuItem;
BZ_GUANYU: TMenuItem;
StatusBar1: TStatusBar;
Timer1: TTimer;
N16: TMenuItem;
JICHUBIAOGZ: TMenuItem;
N17: TMenuItem;
OpenPictureDialog1: TOpenPictureDialog;
N8: TMenuItem;
BeiJing: TMenuItem;
N15: TMenuItem;
KLXG: TMenuItem;
CHA_JD: TMenuItem;
CHA_FH: TMenuItem;
TJ_LSLL: TMenuItem;
TJ_TONGJI: TMenuItem;
Timer2: TTimer;
Timer3: TTimer;
BD_DanWei: TMenuItem;
N3: TMenuItem;
LingChang_ChaX: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
MDIWallpaper1: TMDIWallpaper;
PopupMenu1: TPopupMenu;
N13: TMenuItem;
N18: TMenuItem;
N19: TMenuItem;
procedure XT_EXITClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure XT_ZHUOMIANClick(Sender: TObject);
procedure N15Click(Sender: TObject);
procedure BeiJingClick(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure N13Click(Sender: TObject);
procedure N18Click(Sender: TObject);
procedure N19Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
WindowList: Pointer;
procedure CreateParams(var Params:TCreateParams);override;
procedure RestoreRequest(var message:TMessage);message CM_RESTORE;
end;
var
frm_Main: Tfrm_Main;
OldCursor:TCursor;
implementation
uses login;
{$R *.DFM}
procedure Tfrm_Main.XT_EXITClick(Sender: TObject);
begin
close;
end;
procedure Tfrm_Main.FormShow(Sender: TObject);
var
MyIni:TIniFile;
name:string;
begin
StatusBar1.Panels[0].Text :='欢迎使用人力资源管理系统!';
//StatusBar1.Panels[1].Text :='单位名称:'+frm_login.unitname;
//StatusBar1.Panels[2].Text:='用户名称:'+frm_login.username;
StatusBar1.Panels[4].Text:=DateToStr(now);
Application.HintHidePause :=5000;
Application.HintPause :=0;
MyIni:=TIniFile.Create('c:/test.ini');
name:=MyIni.ReadString('path','name','');
if name<>'' then
begin
if FileExists(name) then
MDIWallpaper1.Picture.LoadFromFile(name);
end;
end;
procedure Tfrm_Main.Timer1Timer(Sender: TObject);
begin
StatusBar1.Panels[3].Text:=TimeToStr(Time);
end;
procedure Tfrm_Main.FormCreate(Sender: TObject);
begin
EnableMenuItem(GetSystemMenu(frm_Main.Handle,False),SC_CLOSE,MF_GRAYED);
end;
procedure Tfrm_Main.XT_ZHUOMIANClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
MDIWallpaper1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
procedure Tfrm_Main.N15Click(Sender: TObject);
begin
close;
end;
procedure Tfrm_Main.BeiJingClick(Sender: TObject);
var
MyIni:TIniFile;
begin
if OpenPictureDialog1.Execute then
begin
MDIWallpaper1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
MyIni:=TIniFile.Create('c:/test.ini');
MyIni.WriteString('path','name',OpenPictureDialog1.Filename);
end;
end;
procedure Tfrm_Main.Timer2Timer(Sender: TObject);
begin
StatusBar1.Panels[0].Text :=' '+StatusBar1.Panels[0].Text;
if length(StatusBar1.Panels[0].Text)=Length('欢迎使用人力资源管理系统!')+68 then
begin
statusBar1.Panels[0].Text:='欢迎使用人力资源管理系统!';
//Timer2.Enabled :=False;
//TImer3.Enabled :=True;
end;
end;
procedure Tfrm_Main.Timer3Timer(Sender: TObject);
var
str:string;
begin
str:=StatusBar1.Panels[0].Text;
DELETE(str,1,1);
StatusBar1.Panels[0].Text :=str;
if length(StatusBar1.Panels[0].Text)=Length('欢迎使用人力资源管理系统!') then
begin
Timer2.Enabled :=True;
TImer3.Enabled :=False;
end;
end;
procedure Tfrm_Main.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WinClassName:=APPNAME;
end;
procedure Tfrm_Main.RestoreRequest(var message: TMessage);
begin
MessageBox(Handle,'程序-'+APPNAME+'已经运行了.','信息',MB_OK+MB_ICONINFORMATION+MB_SYSTEMMODAL);
if IsIconic(Application.Handle)=TRUE then
Application.Restore
else
Application.BringToFront;
end;
procedure Tfrm_Main.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbright then
PopupMenu1.Popup(x,y+40);
end;
procedure Tfrm_Main.N13Click(Sender: TObject);
begin
MDIWallpaper1.Mode:=wpCenter;
end;
procedure Tfrm_Main.N18Click(Sender: TObject);
begin
MDIWallpaper1.Mode:=wpTile;
end;
procedure Tfrm_Main.N19Click(Sender: TObject);
begin
MDIWallpaper1.Mode:=wpStretch;
end;
end.
其中主窗体、数据模块是auto-create forms,闪现窗体、登录窗体是available forms。是
在progject的options中设置的。