声明的区别(100分)

  • 主题发起人 主题发起人 QianQi
  • 开始时间 开始时间
Q

QianQi

Unregistered / Unconfirmed
GUEST, unregistred user!

求赐教以下几种声明方式的区别和哪种是错误的:
1.unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyDataType=Record
Name:String;
Amount:Real;
Items:Integer;
Paid:Boolean;
end;
TMyDataObject=Class(TObject)
private
MyData:TMyDataType;
published
Constructor Create(Name:String);
Destructor Free;
Procedure SetRecord(var Rec:TMyDataType);
Procedure GetRecord(var Rec:TMyDataType);
end;
type
MyComponent=Class(TComponent)
private
FRecord:TMyDataType;
published
Property TheRecord:TMyDataType Read FRecord Write FRecord;
end;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.

2.unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyDataType=Record
Name:String;
Amount:Real;
Items:Integer;
Paid:Boolean;
end;
TMyDataObject=Class(TObject)
MyComponent=Class(TComponent)
private
MyData:TMyDataType;
FRecord:TMyDataType;
published
Constructor Create(Name:String);
Destructor Free;
Procedure SetRecord(var Rec:TMyDataType);
Procedure GetRecord(var Rec:TMyDataType);
Property TheRecord:TMyDataType Read FRecord Write FRecord;
end;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.

3.unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyDataType=Record
Name:String;
Amount:Real;
Items:Integer;
Paid:Boolean;
end;
type
TMyDataObject=Class(TObject)
MyComponent=Class(TComponent)
TForm1 = class(TForm)
private
{ Private declarations }
MyData:TMyDataType;
FRecord:TMyDataType;
public
{ Public declarations }
published
Constructor Create(Name:String);
Destructor Free;
Procedure SetRecord(var Rec:TMyDataType);
Procedure GetRecord(var Rec:TMyDataType);
Property TheRecord:TMyDataType Read FRecord Write FRecord;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.

4.unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyDataType=Record
Name:String;
Amount:Real;
Items:Integer;
Paid:Boolean;
end;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
type
TMyDataObject=Class(TObject)
MyComponent=Class(TComponent)
private
MyData:TMyDataType;
FRecord:TMyDataType;
published
Constructor Create(Name:String);
Destructor Free;
Procedure SetRecord(var Rec:TMyDataType);
Procedure GetRecord(var Rec:TMyDataType);
Property TheRecord:TMyDataType Read FRecord Write FRecord;
end;

{$R *.DFM}
end.

5.unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TMyDataType=Record
Name:String;
Amount:Real;
Items:Integer;
Paid:Boolean;
end;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
type
TMyDataObject=Class(TObject)
MyComponent=Class(TComponent)
private
MyData:TMyDataType;
FRecord:TMyDataType;
published
Constructor Create(Name:String);
Destructor Free;
Procedure SetRecord(var Rec:TMyDataType);
Procedure GetRecord(var Rec:TMyDataType);
Property TheRecord:TMyDataType Read FRecord Write FRecord;
end;

end.
 
这么多,看都看晕了。
好象都对,不同是有的数据类型其他unit不能使用(在implementation后声明的)
 
晕倒前发现:
1)方法一中:
published
Property TheRecord:TMyDataType Read FRecord Write FRecord;
流机制并不支持自定义的类型
2)Destructor Free;
建议重载Destroy;而不是Free;

 
已经晕倒,醒来后发觉:
把TMyDataType专门定义在一个单元,其它单元要用就包含这个单元就是了
 
我也晕了。
最起码应该标出不同的地方。
read write 应该是简单类型,
 
多谢四位,每人25分。
 
多人接受答案了。
 
后退
顶部