小鱼nansha请各位大鲨我诊断一下---登陆密码的问题(30分)

  • 主题发起人 主题发起人 nansha
  • 开始时间 开始时间
N

nansha

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm7.suiButton1Click(Sender: TObject);
var
results:variant;
begin
count:=count+1;
results:=adotable1.Lookup('yhm',suiedit1.Text,'mm');
if results=suiedit2.Text then
begin
form2.suiButton1.Enabled:=true;
Self.ModalResult:=mrOK;
end
else
begin
showmessage('哈哈,用户名或密码错误!');
if (count=3) then close;
end;
end;
运行时出现错误:跳出一名为Debugger Exception Notification的窗体
窗体内容为:project tianyetel.exe raised exception class EAccessViolation with message 'Accessviolation at address
004F1160 in module 'tianyetel.exe'.READ OF Address 00000328'.
process stoped.Use Step or Run to continue.
不知为什么,我只是想在密码验证后改变另一个窗体的button的enabled属性!
 
取消Self.ModalResult:=mrOK;试一试!
 
可能是第二个窗体还没有创建
 
同意楼上,可能是有窗体没有创建
 
创建了呀,是这样的,我在form2中有个登陆按钮,点击后进入form7登陆窗体,然后在form7中通过密码验证改变form2中的button的enabled属性
 
我在工程文件中没有加Application.CreateForm(TForm2, Form2);也就没有创建窗体!
而是在mainform中用tform2.Create(self);创建的窗体!
现在是如何把Application.CreateForm(TForm2, Form2);在mainform中的tform2.Create(self);后写入到工程文件中?
 
在program中看看form2是否在此窗体前创建
 
你有没有USES呢?
 
我知道原因是我没在工程文件中创建Application.CreateForm(TForm2, Form2);
的缘故,我的窗体是mdi,我想动态创建该窗体,如果我在程序中创建,就无法运行!
我的目的:我想在子窗体form7中改变子窗体form2的button的enabled属性,如果formstyle=fsnormal就可以在程序中
改变另一窗体的button的属性,但在mdi就无法在子窗体中改变另一子窗体的button属性!
????????????????
 
可以在MDI子窗体中改变另一个子窗体的Button属性,但必须子窗体都打开,新建一个Application,
三个窗体,一个为MDIForm,另外两个为MDIChildForm,在工程文件中不不创建另外两个窗体,
主窗体代码:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Open1: TMenuItem;
Open21: TMenuItem;
procedure Open1Click(Sender: TObject);
procedure Open21Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2, Unit3;

{$R *.dfm}

procedure TForm1.Open1Click(Sender: TObject);
begin
ShowForm2;
end;

procedure TForm1.Open21Click(Sender: TObject);
begin
ShowForm3;
end;

end.

MDI子窗体1代码
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ShowForm2;
var
Form2: TForm2;

implementation

{$R *.dfm}
procedure ShowForm2;
begin
if not Assigned(Form2) then
Form2:=TForm2.Create(Application);
with Form2 do
begin
Show;
SetFocus;
end;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;

end.

MDI子窗体2代码

unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm3 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ShowForm3;
var
Form3: TForm3;

implementation

uses Unit2;

{$R *.dfm}
procedure ShowForm3;
begin
if not Assigned(Form3) then
Form3:=TForm3.Create(Application);
with Form3 do
begin
Show;
SetFocus;
end;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;

procedure TForm3.Button1Click(Sender: TObject);
begin
Form2.Button1.Enabled:=False;
end;

end.

该程序运行,首先使用MDI窗体的菜单打开两个MDI子窗体,然后在Form3中(也就是第二个MDI子窗体)
单击Button1,设置Form2(第一个子窗体)Button1的Enable为False;

工程文件代码:

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
 
多人接受答案了。
 
后退
顶部