unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyForm = class(TForm)
private
public
constructor Create(Owner: TComponent; x: Integer);overload;
end;var
Form1: TForm1;implementation{$R *.dfm}constructor TMyForm.Create(Owner: TComponent; x: Integer);
begin
inherited Create(Owner);
showmessage('construceedf');
end;procedure TForm1.Button1Click(Sender: TObject);
var
my: TMyForm;
begin
my := TMyForm.Create(nil,8);
my.Caption := 'sss';
end;end.我的代码有什么问题,编译通过了,但一运行就报错。
'resource TMyForm not Found'
请解释一个问什么?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyForm = class(TForm)
private
public
constructor Create(Owner: TComponent; x: Integer);overload;
end;var
Form1: TForm1;implementation{$R *.dfm}constructor TMyForm.Create(Owner: TComponent; x: Integer);
begin
inherited Create(Owner);
showmessage('construceedf');
end;procedure TForm1.Button1Click(Sender: TObject);
var
my: TMyForm;
begin
my := TMyForm.Create(nil,8);
my.Caption := 'sss';
end;end.我的代码有什么问题,编译通过了,但一运行就报错。
'resource TMyForm not Found'
请解释一个问什么?
TMyForm = class(TForm)
private
public
constructor Create(Owner: TComponent; x: Integer);overload;
end;
粘贴的时候不小心删了 ‘end;’再加上。其它不变。
begin
GlobalNameSpace.BeginWrite;
try
CreateNew(Owner);
finally
GlobalNameSpace.EndWrite;
end;
showmessage('construceedf');
end;
TMyForm = class(TForm)
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyForm = class(TForm)//改到上面
{ Private declarations }
public
{ Public declarations }
end;
type ******************這加入就可以了
TMyForm = class(TForm)
private
public
constructor Create(Owner: TComponent; x: Integer);overload;
end;
代码就如同我前面贴的那样,但一点BUTTON就报错。说xxxxxxxx地址错误。
代码停在ShowMessage那一行。我再贴一次:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyForm = class(TForm)
private
public
constructor Create(Owner: TComponent; i: Integer);reintroduce;overload;
end;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}constructor TMyForm.Create(Owner: TComponent;i: Integer);
begin
inherited Create(Owner);
ShowMessage('sdfsd');
end;procedure TForm1.Button1Click(Sender: TObject);
var
m: TMyForm;
begin
m := TMyForm.Create(nil,8);
m.Show;
end;end.
的 overload 去掉,实际上不是重载 而是改写 我上面写的错le
不需要加上 override...
overload 是不能改成 override 的 很明显楼主重新写了构造函数 改成override
编译根本不能通过 override 只能用于先后两次声明格式完全相同的情况
楼主的错误在于把两个form 放在一个unit 里 这样在生成第2个窗体的时候必然会
使得资源不够用 建议楼主把TMyform 放到别的Form下(别的Unit下也是会发生资源不足的,只能new form )这样问题应该能得到解决
---新手的拙见 仅供参考
你没有看清楚吗?我是动态生成一个窗体.我觉得问题很简单,希望各位能试着自己
不管是改成OVERRIDE不是OVERLOAD.
我的代码可以编译过去,但一点击BUTTON就报错.
不知道各位是不是试过点那个 BUTTON.看看是什么情况.