我刚开始接触这个技术,还有很多需要学习。
PNode = ^TNode;
TNode = record
Obstacle : boolean;
Visited : boolean;
GCost : double; // Distance from Starting Node
HCost : double; // Distance from Target Node
x : integer;
y : integer;
vecNeighBour : array of PNode;
Parent : PNode;
end;
在FormShow事件中,我填充了该数组:
SetLength(Node,4,4);
Image1.Height:=Length(Node)*50;
Image1.Width:=Length(Node)*50;
for x := Low(Node) to High(Node) do
for y := Low(Node) to High(Node) do
begin
Node[x,y].Obstacle:=false;
Node[x,y].Visited:=false;
Node[x,y].GCost:=infinity;
Node[x,y].HCost:=infinity;
Node[x,y].x:=x;
Node[x,y].y:=y;
end;
现在我想按照 HCost 对这个数组进行排序,所以我尝试了以下代码。
TArray.Sort<TNode>(Node , TComparer<TNode>.Construct(
function(const Left, Right: TNode): double
begin
if Left.HCost > Right.HCost then
Result:=Left.HCost
else
Result:=Right.HCost;
end));
我在这方面的知识严重不足。我从Delphi中得到一个错误提示:
"Incompatible types: 'System.Generics.Defaults.TComparison'和'Procedure'"
我做错了什么呢?