在mainForm中要TfrmImport.Create(nil,'key')来传递一个key给frmImort,结果总是有错误或者告警原来以前很简单的东西:
constructor Create(AOwner: TComponent;Key:string);override;提示
[Error] untLocate.pas(18): Declaration of 'Create' differs from previous declaration
[Error] untLocate.pas(32): Unknown directive: 'override'
不知道了原因,谁HELP一下(最后即个最简单的工程试一下,我也以为非常简单,结果总是不对)
constructor Create(AOwner: TComponent;Key:string);override;提示
[Error] untLocate.pas(18): Declaration of 'Create' differs from previous declaration
[Error] untLocate.pas(32): Unknown directive: 'override'
不知道了原因,谁HELP一下(最后即个最简单的工程试一下,我也以为非常简单,结果总是不对)
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations } public
constructor Create(AOwner: TComponent); override;
published { Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
{ TForm1 }{ TForm1 }constructor TForm1.Create(AOwner: TComponent);
begin
inherited;end;end.
结果在override(overload) create方法的时候老是提示有错误!或者warnings上面的构造函数的参数没有改变,自然是不会有错误的了 constructor Create(AOwner: TComponent); override;
constructor TForm1.Create(AOwner: TComponent;key:String);
begin
inherited;
self.caption := Key ;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
constructor Create(AOwner: TComponent;Key:String); override;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}constructor TForm1.Create(AOwner: TComponent;key:String);
begin
inherited;
self.caption := Key ;
end;
end.
编译:
[Error] Unit1.pas(14): Declaration of 'Create' differs from previous declaration
[Error] Unit1.pas(27): Incompatible types
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
constructor Create(AOwner: TComponent;Key:String); constructor TForm1.Create(AOwner: TComponent;key:String);
begin
self.caption := Key ;
inherited Create(self);
end;
constructor Create(AOwner: TComponent;Key:String); Overload;constructor TForm1.Create(AOwner: TComponent;key:String);
begin
self.caption := Key ;
inherited Create(self);
end;数
constructor Create(AOwner: TComponent;Key:String); Overload;
procedure TForm2.Button1Click(Sender: TObject);
begin
TForm1.Create(self,'hello');
Form1.Show;
end;
Form1的CREATE方法:
begin
self.caption := Key ;
inherited Create(self);
end;
TForm的Create继承自TCustomForm
一,如果声明为:constructor Create(AOwner: TComponent;Key:String); Overload;
编译错误是:
[Warning] Unit1.pas(15): Method 'Create' hides virtual method of base type 'TCustomForm'
在TForm2.Button1Click(Sender: TObject);的时候将出现:access violation .....二,如果声明为:constructor Create(AOwner: TComponent;Key:String); Override;
[Error] Unit1.pas(14): Declaration of 'Create' differs from previous declaration三,如果是constructor Create(AOwner: TComponent;Key:String);
和一的情况一样
真怀疑是不是这个TCustomform的create是不是有点特别
constructor TForm2.Create(AOwner: TComponent; Key: String);
begin
TForm1(AOwner).caption := Key ;
inherited Create(AOwner);end;
成功!接分