请教各位大神,这个delphi的mdi子窗口执行不下去怎么办???
delphi吧
全部回复
仅看楼主
level 1
Form1:fsMDIForm;
Form2:fsMDIChild;
//以下是Form2的全部代码-----------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure ReadEdit1;
begin
ShowMessage(form2.Edit1.Text);//问题就在这里,为什么这个过程执行报错。为什么执行过程或函数不能调用mdi子窗口中的控件内容?????????!!!!!!!!
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
ReadEdit1;
end;
end.
//以下是Form1的全部代码-----------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
b1: TMenuItem;
procedure b1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.b1Click(Sender: TObject);
var
newform:TForm2;
i,flag:integer;
begin
flag:=0;
for i:=0 to Form1.MDIChildCount-1 do
begin
if Form1.MDIChildren[i].Caption='Form2' then
begin
SendMessage(mdichildren[i].Handle, WM_SYSCOMMAND, SC_restore, 0);
mdichildren[i].Show;
mdichildren[i].Enabled:=true;
flag:=1;
mdichildren[i].top:=0;
mdichildren[i].Left:=0;
break;
end;
end;
if flag=0 then
begin
newform:=Tform2.Create(application);
newform.Caption:='Form2';
newform.Top:=0;
newform.Left:=0;
newform.Height:=Form1.ClientHeight-24;
newform.Width:=Form1.ClientWidth-4;
end;
end;
end.
2016年02月17日 06点02分 1
level 1
2016年02月17日 06点02分 3
level 12
自己调试的时候,
看看你的
Form2是个啥吧.
2016年02月18日 01点02分 4
level 1
上面的图就是运行结果。非常奇怪,在Form2的Unit写下的一个简单调用Form2上控件内容的过程,竟然报错。这究竟是为什么呢?~~~~~求解
2016年02月18日 03点02分 5
level 8
也许是你的 ReadEdit1 没有在接口中声明,如果把showmessage放在 Button1Click 里面也许就没错了。
可以试下。
2016年02月23日 01点02分 7
1