陈
陈君凯
Unregistered / Unconfirmed
GUEST, unregistred user!
我碰到了一个很离谱的问题.form1是闪现窗体,form2是主窗体,form3.form4为一般窗体.
由form2到3.4窗体可以,但从3,4窗体到2窗体就会出现程序非法操作,真怪!不止为何?
源程序如下:
program inject;
uses
Forms,
SysUtils,
windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas' {Form4};
{$R *.RES}
var
time1:longint;
begin
application.Initialize;
Form1:=TForm1.Create(application);
Form1.Show;
Form1.Update;
time1:=GetTickCount div 1000;
while (LongInt(GetTickCount div 1000)<(Time1+3))do
;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.Run;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, GIFImage, jpeg, ExtCtrls;
type
TForm2 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Image3: TImage;
procedure FormShow(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1,unit3,unit4;
{$R *.DFM}
procedure TForm2.FormShow(Sender: TObject);
begin
form1.free;
end;
procedure TForm2.BitBtn3Click(Sender: TObject);
begin
form2.Close;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
Form2.Hide;
Form3.Show;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
Form2.Hide;
Form4.Show;
end;
end.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TForm3 = class(TForm)
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses unit2;
{$R *.DFM}
procedure TForm3.BitBtn1Click(Sender: TObject);
begin
Form2.Show;
Form3.Hide;
end;
end.
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TForm4 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses unit2;
{$R *.DFM}
procedure TForm4.Button1Click(Sender: TObject);
begin
Form4.Hide;
Form2.Show;
end;
end.
由form2到3.4窗体可以,但从3,4窗体到2窗体就会出现程序非法操作,真怪!不止为何?
源程序如下:
program inject;
uses
Forms,
SysUtils,
windows,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3},
Unit4 in 'Unit4.pas' {Form4};
{$R *.RES}
var
time1:longint;
begin
application.Initialize;
Form1:=TForm1.Create(application);
Form1.Show;
Form1.Update;
time1:=GetTickCount div 1000;
while (LongInt(GetTickCount div 1000)<(Time1+3))do
;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.CreateForm(TForm4, Form4);
Application.Run;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, GIFImage, jpeg, ExtCtrls;
type
TForm2 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Image3: TImage;
procedure FormShow(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1,unit3,unit4;
{$R *.DFM}
procedure TForm2.FormShow(Sender: TObject);
begin
form1.free;
end;
procedure TForm2.BitBtn3Click(Sender: TObject);
begin
form2.Close;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
Form2.Hide;
Form3.Show;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
Form2.Hide;
Form4.Show;
end;
end.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TForm3 = class(TForm)
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses unit2;
{$R *.DFM}
procedure TForm3.BitBtn1Click(Sender: TObject);
begin
Form2.Show;
Form3.Hide;
end;
end.
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TForm4 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
uses unit2;
{$R *.DFM}
procedure TForm4.Button1Click(Sender: TObject);
begin
Form4.Hide;
Form2.Show;
end;
end.