TLoginFrm中的BitBtn1属性Default:=False,ModalResult:=mrNone,Kind:=bkCustom
问题:我只要按一下BitBtn1后,程序就报错,报错提示:
Project zero.exe raised exception class EAccessViolation with message 'Access violation at address 4B49CD85. Read of address 4B49CD85'. Process stopped.Use Step or Run to continue.
真是奇怪,这个程序我几乎没有写什么代码,只给BitBtn1的Onclick事件中写了一句代码。但在程序运行中按下BitBtn1就报错。
在Project中Options选项里面我将MainForm和LoginFrm都移到Available Forms中了。
Auto-create forms中只有一个DataModule1.源代码如下:
program Zero;uses
Forms,
Controls,
SysUtils,
ZeroMain in 'ZeroMain.pas' {MainForm},
ZeroLogin in 'ZeroLogin.pas' {LoginFrm},
ZeroDM in 'ZeroDM.pas' {DataModule1: TDataModule};{$R *.res}
var
LoginForm:TLoginFrm;
begin
Application.Initialize;
Application.CreateForm(TDataModule1, DataModule1);
LoginForm:=TLoginFrm.Create(Application);
if LoginForm.ShowModal=mrOk then
begin
FreeAndNil(LoginForm);
Application.CreateForm(TMainForm,MainForm);
Application.Run;
end;
end.==========================
unit ZeroLogin;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;type
TLoginFrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Button1: TButton;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;implementation{$R *.dfm}procedure TLoginFrm.BitBtn1Click(Sender: TObject);
begin
ModalResult:=mrCancel;
end;
==============================
unit ZeroMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TMainForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.dfm}end.以前我写过这种登录代码,没有遇到过错,我对照以前的代码,没有什么区别,但这次不知为何按BitBtn1这里总报错。
还请大侠们指点,谢谢!
问题:我只要按一下BitBtn1后,程序就报错,报错提示:
Project zero.exe raised exception class EAccessViolation with message 'Access violation at address 4B49CD85. Read of address 4B49CD85'. Process stopped.Use Step or Run to continue.
真是奇怪,这个程序我几乎没有写什么代码,只给BitBtn1的Onclick事件中写了一句代码。但在程序运行中按下BitBtn1就报错。
在Project中Options选项里面我将MainForm和LoginFrm都移到Available Forms中了。
Auto-create forms中只有一个DataModule1.源代码如下:
program Zero;uses
Forms,
Controls,
SysUtils,
ZeroMain in 'ZeroMain.pas' {MainForm},
ZeroLogin in 'ZeroLogin.pas' {LoginFrm},
ZeroDM in 'ZeroDM.pas' {DataModule1: TDataModule};{$R *.res}
var
LoginForm:TLoginFrm;
begin
Application.Initialize;
Application.CreateForm(TDataModule1, DataModule1);
LoginForm:=TLoginFrm.Create(Application);
if LoginForm.ShowModal=mrOk then
begin
FreeAndNil(LoginForm);
Application.CreateForm(TMainForm,MainForm);
Application.Run;
end;
end.==========================
unit ZeroLogin;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;type
TLoginFrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Button1: TButton;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;implementation{$R *.dfm}procedure TLoginFrm.BitBtn1Click(Sender: TObject);
begin
ModalResult:=mrCancel;
end;
==============================
unit ZeroMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TMainForm = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.dfm}end.以前我写过这种登录代码,没有遇到过错,我对照以前的代码,没有什么区别,但这次不知为何按BitBtn1这里总报错。
还请大侠们指点,谢谢!
解决方案 »
- 调用外部程序打开外部注册表文件
- 如何获取HTTP里的POST的参数?
- DELPHI的问题
- 连接sybase数据库老是弹出数据库德登陆框,每次都要输入sa和密码什么的,有办法去掉吗?或者设置成自动登陆??
- 一个记录能否存两个以上的图片,并用OLE控件分页读出?
- 在stringgrid 中怎么更新数据
- 过年啦,领分啦,风云公开测试啦......集信息管理,多媒体播放(FLASH,影视,歌曲),图片浏览,网页浏览于一体的...Faint,先用用再说
- 一个过程的设计(分很容易拿的,对高手来说)
- 我在odbc中设置了sql server服务,在程序中却是调用了sql server服务器上的视图(view),如何显示服务器上的表(table)?
- 关于PASCAL的问题
- 如何用DELPHI 备份数据库
- 如何仅显示前10条记录
奇怪呀,以前我有一个程序也是这样写的,没有出错,但这次为何会出错呢?
编译里,在信息框中会有这样的提示:
[Warning] ADODB.pas(2480): Comparison always evaluates to False
[Warning] ADODB.pas(2480): Comparing signed and unsigned types - widened both operands我双击上面的提示,则位置跳到:
function TParameters.CreateParameter(const Name: WideString;
DataType: TDataType; Direction: TParameterDirection; Size: Integer;
Value: OleVariant): TParameter;
begin
Result := AddParameter;
Result.FParameter := Create_Parameter(Name, DataType, Direction, Size);
{ Don't try to assign value when it is an EmptyParam (used when optional) }
[red] if not ((TVarData(Value).VType = varError) and
(TVarData(EmptyParam).VError = $80020004)) then [/red]
Result.FParameter.Value := Value;
end;我用单步执行时,出错的位置是:
procedure TCustomForm.DestroyWindowHandle;
begin
if fsCreatedMDIChild in FFormState then
SendMessage(Application.MainForm.ClientHandle, WM_MDIDESTROY, Handle, 0)
else
inherited DestroyWindowHandle;
[red] FClientHandle := 0;[/red] //停在这条语句上。
end;
var
LoginForm:TLoginFrm;
begin
Application.Initialize;
Application.CreateForm(TDataModule1, DataModule1);
LoginForm:=TLoginFrm.Create(Application);
try
if LoginForm.ShowModal = mrcancel then
Application.terminate;
finally
LoginForm.Free;
end; Application.CreateForm(TMainForm,MainForm);
Application.Run;
end.程序出错的原因好像是,application没有一个运行点,因为点击取消后,程序退出了。而你创建的LoginForm没有释放,