关于DELPHI的继承和多态:这段代码为什么有问题?(在线等)(50分)

  • 主题发起人 主题发起人 冰冷的雨
  • 开始时间 开始时间

冰冷的雨

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,出现错误[Error] uCustom.PAS(43): Unsatisfied forward
or external declaration: 'TExpen.Create'

相关代码如下:
type
TStruct = record
x: integer;
y: integer;
end;

TCustom = class(TObject)
private
FOwner: integer;
FStruct: TStruct;
protected
procedure UpdateCommonnes(AOwner: TStruct);
public
constructor Create
overload;virtual;
constructor Create(AOwner: TStruct)
overload;virtual;
end;

TExpend = class(TCustom)
public
constructor Create
reintroduce;override;
constructor Create(AOwner: TStruct)
reintroduce;override;
end;

implementation

constructor TCustom.Create;
begin
inherited Create;
end;

constructor TCustom.Create(AOwner: TStruct);
begin
inherited Create;
UpdateCommonnes(AOwner);
end;

constructor TCustom.UpdateCommonnes(AOwner: TStruct);
begin
if AOwner<>nil then
FStruct := AOwner;
end;

constructor TExpend.Create;
begin
inherited;
FOwner := 0;
end;

constructor TExpend.CreateCreate(AOwner: TStruct);
begin
inherited;
FOwner := 0

end;
 
TExpend = class(TCustom)
public
constructor Create
override;
constructor Create(AOwner: TStruct)
reintroduce;override;
end;
 
谢谢一条大鱼。按您的说法改了之后还是出一样的错
 
随便试试,发行代码有几个地方有问题,但是就没有你的问题,修改后正常。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TStruct = record
x: integer;
y: integer;
end;

TCustom = class(TObject)
private
FOwner: integer;
FStruct: TStruct;
protected
procedure UpdateCommonnes(AOwner: TStruct);
public
constructor Create
overload;virtual;
constructor Create(AOwner: TStruct)
overload;virtual;
end;

TExpend = class(TCustom)
public
constructor Create
reintroduce;override;
constructor Create(AOwner: TStruct)
reintroduce;override;
end;

TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

constructor TCustom.Create;
begin
inherited Create;
end;

constructor TCustom.Create(AOwner: TStruct);
begin
inherited Create;
UpdateCommonnes(AOwner);
end;

procedure TCustom.UpdateCommonnes(AOwner: TStruct);
begin
FStruct := AOwner;
end;

constructor TExpend.Create;
begin
inherited;
FOwner := 0;
end;

constructor TExpend.Create(AOwner: TStruct);
begin
inherited;
FOwner := 0

end;

end.
 
学习。。。
 
JamesBond_L兄,仔细看了您的代码,您指的几个错误是复制时不小心搞错了。源码没有
那些错误。但错误[Error] uCustomAssets.PAS(43): Unsatisfied forward or external declaration: 'TExpendable.Create'仍存在。实际的源码如下:

type
TAssetsCommonnes = record
...
end;

TCustomAssets = class(TObject)
private
FCommonnes: TAssetsCommonnes;
FKind: string;
protected
function GetAssetsCommonnes(const AttribNames: TList): TList
overload;
function GetAssetsCommonnes: TAssetsCommonnes
overload;
procedure UpdateAssetsCommonnes(const AttribList: TList)
overload;
procedure UpdateAssetsCommonnes(const Value: TAssetsCommonnes)
overload;
property Kind: string read GetKind write SetKind;
public
constructor Create
overload;virtual;
constructor Create(AOwner: TAssetsCommonnes)
overload;virtual;
end;

TExpendable = class(TCustomAssets)
public
constructor Create
reintroduce;override;
constructor Create(AOwner: TAssetsCommonnes)
reintroduce;override;
property Kind;
property Minutia;
end;

implementation

{
******************************** TCustomAssets *********************************
}
constructor TCustomAssets.Create;
begin
// inherited Create;
end;

constructor TCustomAssets.Create(AOwner: TAssetsCommonnes);
begin
UpdateAssetsCommonnes(AOwner);
end;

...

procedure TCustomAssets.UpdateAssetsCommonnes(const Value: TAssetsCommonnes);
begin
end;

{
********************************* TExpendable **********************************
}
constructor TExpendable.Create;
begin
inherited;

Kind := '耗材';
end;

constructor TExpendable.(AOwner: TAssetsCommonnes);
begin
inherited;

Kind := '耗材';
end;
 
谢谢。问题解决,是这段代码错了个字符。
constructor TExpendable.Create(AOwner: TAssetsCommonnes);
begin
inherited;

Kind := '耗材';
end;
 
多人接受答案了。
 
后退
顶部