部分源代码如下:
unit Unit1;
.....
....
uses
GetDataModule;procedure TForm1.Button1Click(Sender: TObject);
var
FModule: TDataModule;
FOperation: TOperation;
begin
FModule:= TDataModule.Create(Self);
FOperation := TOperation.Create(nil);
FOperation.Channels := 88;
FModule.Operations.Add.Channels :=12;
FModule.Operations[0] := FOperation;
FMOdule.Destroy;
end;unit GetDataModule;
....
....
TOperation = class (TComponent)
private
FChannels:integer;
...
public
property Channels: Integer read GetChannels write SetChannels;
constructor Create(AOwner:TOperations);
end; TOperations = class (TObject)
private
FList: TList;
FOwner: TDataModule;
procedure SetOperations(Index: Integer; const Value: TOperation);
function GetOperations(Index: Integer): TOperation;
public
constructor Create(AOwner:TDataModule);
function Add: TOperation;
property Operations[Index: Integer]: TOperation read GetOperations Write SetOperations; default;
end;TDataModule = class (TObject)
private
FOperations: TOperations;
..
..
public
...
constructor Create(AOwner:TComponent);
Property Operations: TOperations read FOperations;
end;constructor TOperations.Create(AOwner:TDataModule);
begin
FList := TList.Create;
end;
function TOperations.Add: TOperation;
var
FOperation: TOperation;
begin
FOperation := TOperation.Create(Self);
FList.Add(FOperation);
Result := TOperation(FList.Items[FList.Count -1]);
end;function TOperations.GetOperations(Index: Integer): TOperation;
begin
Result := (FList.Items[Index]);
end;procedure TOperations.SetOperations(Index: Integer;
const Value: TOperation);
begin
TOperation(FList[Index]).Assign(Value);//ERROR LINE
end;为什么当程序运行到FModule.Operations[0] := FOperation;的时候通过调试发现错误发生在ERROR LINE这里,错误信息为:Cannot Assign A TOperation To A TOperation,请问为什么会出现这个错误?如何解决?还有TA = class of TB代表什么意思?请各位帮帮忙,如果分不够可以另外开帖
unit Unit1;
.....
....
uses
GetDataModule;procedure TForm1.Button1Click(Sender: TObject);
var
FModule: TDataModule;
FOperation: TOperation;
begin
FModule:= TDataModule.Create(Self);
FOperation := TOperation.Create(nil);
FOperation.Channels := 88;
FModule.Operations.Add.Channels :=12;
FModule.Operations[0] := FOperation;
FMOdule.Destroy;
end;unit GetDataModule;
....
....
TOperation = class (TComponent)
private
FChannels:integer;
...
public
property Channels: Integer read GetChannels write SetChannels;
constructor Create(AOwner:TOperations);
end; TOperations = class (TObject)
private
FList: TList;
FOwner: TDataModule;
procedure SetOperations(Index: Integer; const Value: TOperation);
function GetOperations(Index: Integer): TOperation;
public
constructor Create(AOwner:TDataModule);
function Add: TOperation;
property Operations[Index: Integer]: TOperation read GetOperations Write SetOperations; default;
end;TDataModule = class (TObject)
private
FOperations: TOperations;
..
..
public
...
constructor Create(AOwner:TComponent);
Property Operations: TOperations read FOperations;
end;constructor TOperations.Create(AOwner:TDataModule);
begin
FList := TList.Create;
end;
function TOperations.Add: TOperation;
var
FOperation: TOperation;
begin
FOperation := TOperation.Create(Self);
FList.Add(FOperation);
Result := TOperation(FList.Items[FList.Count -1]);
end;function TOperations.GetOperations(Index: Integer): TOperation;
begin
Result := (FList.Items[Index]);
end;procedure TOperations.SetOperations(Index: Integer;
const Value: TOperation);
begin
TOperation(FList[Index]).Assign(Value);//ERROR LINE
end;为什么当程序运行到FModule.Operations[0] := FOperation;的时候通过调试发现错误发生在ERROR LINE这里,错误信息为:Cannot Assign A TOperation To A TOperation,请问为什么会出现这个错误?如何解决?还有TA = class of TB代表什么意思?请各位帮帮忙,如果分不够可以另外开帖
解决方案 »
- delphi 在文本文件每行添加字符串??????????????????????(非计算机专业还有这么复杂的文本操作题??)
- Delphi 调用API做的完成端口出现 10055错误,请高手指点~~
- WebBrowser的问题!
- delphi 电子书求助
- 难题!从 EXE 里面取出来的图标全是16色的?如何保存成 16 位颜色的?
- Delphi的安装问题:安装之初如何解决:BDE is currently running
- 请问在D7下用batchmove拷贝一个数据库,怎样做进度条?
- 大家都是把TQUERY等放到DATAMODULE里的吗,但是。。。
- 最新调查!
- 我的问题有点难
- 动态生成报表出现异常
- DELPHI入门级问题,但我难住了,郁闷中!!!
修改為
TOperations = class (TControl)
試下
Only the common properties shared by both source and destination Series are copied.TOperation = class (TComponent) ,but
TOperations = class (TObject);2.A class-reference type, sometimes called a metaclass, is denoted by a construction of the formclass of typewhere type is any class type. The identifier type itself denotes a value whose type is class of type. If type1 is an ancestor of type2, then class of type2 is assignment-compatible with class of type1. Thustype TClass = class of TObject;
var AnyObj: TClass;declares a variable called AnyObj that can hold a reference to any class. (The definition of a class-reference type cannot occur directly in a variable declaration or parameter list.) You can assign the value nil to a variable of any class-reference type.To see how class-reference types are used, look at the declaration of the constructor for TCollection (in the Classes unit):type TCollectionItemClass = class of TCollectionItem;
...
constructor Create(ItemClass: TCollectionItemClass);This declaration says that to create a TCollection instance object, you must pass to the constructor the name of a class descending from TCollectionItem.Class-reference types are useful when you want to invoke a class method or virtual constructor on a class or object whose actual type is unknown at compile time.TA = class of TB ,
表示TA是继承TB的类;
表示TA是一个类TB的类型,而不是继承
const Value: TOperation);
begin
FList[Index]:=Value
end;
还有TA= class of TB到底是什么意思?它和类的继承有什么区别呢?
表示TA是一个类TB的类型,