目的是给TForm_SDALL类加一个新属性TblName:String,调用动态生成实例并给TblName赋值.//(1)单元文件内容
unit SDALL;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, DBGridEh;type
TForm_SDALL = class(TForm)
public
constructor create;overload;
TblName:String;
constructor create(const str:String);overload;
end;var
Form_SDALL: TForm_SDALL;implementation
uses MAINMENU;{$R *.dfm}PROCEDURE TForm_SDALL.create(str:String);
begin
inherited Create;
TblName:=str;
end;end.
//(2)在另一个地方引用时出错
var
myForm:TForm;
begin
myForm:=TForm_SDALL.Create('SSS'); //这句编译时出错,说 Incompatible types: 'TComponent' and 'String'
end;
unit SDALL;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, Grids, DBGridEh;type
TForm_SDALL = class(TForm)
public
constructor create;overload;
TblName:String;
constructor create(const str:String);overload;
end;var
Form_SDALL: TForm_SDALL;implementation
uses MAINMENU;{$R *.dfm}PROCEDURE TForm_SDALL.create(str:String);
begin
inherited Create;
TblName:=str;
end;end.
//(2)在另一个地方引用时出错
var
myForm:TForm;
begin
myForm:=TForm_SDALL.Create('SSS'); //这句编译时出错,说 Incompatible types: 'TComponent' and 'String'
end;
解决方案 »
- delphi。。当鼠标移动时,如何获得屏幕当前的鼠标的坐标。。。
- 随机触发问题
- 急,用delphi写asp传送过来的信息保存到数据库中,怎么总是有问题?
- Delphi7的两简单问题!200分!在线等候!
- 急!!!,在dbgrid1中我想把查找到的所有记录中字段(金额)的总和在edit1中显示出来?
- 救命!救命
- 如何将Delphi中的包转换为ocx.
- 如何去掉bitmap的黑背景!
- Delphi中如何实现EXE文件的自定义节[Section],在进程问共享数据???
- 那里有mci函数的详细说明,知道的帮帮忙!
- 求助:Delphi里有没有指向类的指针?
- VirtualTreeview应用高手请进!!
public
constructor create(str:String);//这里改成这样
TblName:String;
constructor create(const str:String);overload;
end;
begin
inherited Create(AOwner);
TblName:=str;
end;
begin
inherited Create(AOwner);
TblName:=str;
end;
按您的做了,问题依旧.TO: tonylk(=www.tonixsoft.com=)
按您的做了,调用也得跟着改成
TForm_SDALL.Create(nil,'SSS'); 或者
TForm_SDALL.Create(application,'SSS');
都会出现 [Error]: Too many actual parameters .看起来,好象它还是在调用重载前的默认create,这个是只有一个参数的,而参数类型就为TComponent.
按您的来,调用
TForm_SDALL.Create(application,'SSS');
也会出现 [Error]: Too many actual parameters
begin
inherited Create(AOwner);
TblName:=str;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm2 = class(TForm)
private
{ Private declarations }
public
TblName:String;
constructor create; reintroduce;overload;
constructor create(const str:String);overload;
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}{ TForm2 }constructor TForm2.create;
begin
inherited Create(Application);
end;constructor TForm2.create(const str: String);
begin
inherited Create(Application);
TblName:=str;
end;end.
inherited Create(Application);
改为
inherited Create(FAowner);
这样就和原来完全兼容了
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
Constructor Create(Text:string); reintroduce ; overload;
end;var
Form1: TForm1;implementation{$R *.dfm}
Constructor TForm1.Create(Text:string);
begin
inherited Create(Application);
showmessage(text);
end;