我在一个类的外面定义了一个record
type
nerveCell = record
....
weight: array of double; //动态数组
....
end;TInputLevel = array[0..inputLevelNo - 1] of nerveCell;然后定义了一个类:
TBP = class(TObject)
private
FInputLevel: TinputLevel; //定义一个数组,数组元素是nerveCell public
function getInputLevelElementWeight(I: integer): double;
property InputLevelElementWeight[I: integer]: double read
getInputLevelElementWeight write setInputLevelElementWeight;
end;//end class definiation
我想写一个getInputLevelElementWeight函数,返回record里面的weight数组,可是这样的函数却编译不过:
function TBP.getInputLevelElementWeight(I: integer): double;
begin
if (I >= 0) and (I < Length(FInputLevel)) then
result := FInputLevel[I].weight;
end;
应该怎样写呢?
type
nerveCell = record
....
weight: array of double; //动态数组
....
end;TInputLevel = array[0..inputLevelNo - 1] of nerveCell;然后定义了一个类:
TBP = class(TObject)
private
FInputLevel: TinputLevel; //定义一个数组,数组元素是nerveCell public
function getInputLevelElementWeight(I: integer): double;
property InputLevelElementWeight[I: integer]: double read
getInputLevelElementWeight write setInputLevelElementWeight;
end;//end class definiation
我想写一个getInputLevelElementWeight函数,返回record里面的weight数组,可是这样的函数却编译不过:
function TBP.getInputLevelElementWeight(I: integer): double;
begin
if (I >= 0) and (I < Length(FInputLevel)) then
result := FInputLevel[I].weight;
end;
应该怎样写呢?
result是double型,而FInputLevel[I].weight是一个数组型,类型不匹配啊。
procedureTBP.getInputLevelElementWeight(I: integer;var aWeight: array of double);
begin
if (I >= 0) and (I < Length(FInputLevel)) then
begin
setlength();//给aWeight 设定长度
aWeight := FInputLevel[I].weight;
end;
end;
result := FInputLevel[I].weight[j];
j是你定义的另一个整型变量,来返回WEIGHT数组的元素。
-----------------------------------------------
写成“返回一个指针”的形式该怎么样写呢?我想把这个函数用在
property InputLevelElementWeight[I: integer]: double read getInputLevelElementWeight
中。
如果采用参数回调,那么这个函数可以改成过程的形式,写在read后面吗?
参数回调:
procedure TBP.getInputLevelElementWeight(I: integer; var aWeight: array of double);
begin
if (I >= 0) and (I < Length(FInputLevel)) then
aWeight := FInputLevel[I].weight; //出错的地方
end;
出现:Incompatible types: 'Array' and 'dynamic array'
错误,怎么样改正?
把 InputLevelElementWeight属性定义成一个动态double型数组那样子的属性,该怎么定义?