我使用以下代码获得“预期的常量表达式”错误:
{
"access_token": "Mg5oQAzt9RLSUezxPYNQ7JRcJqo-uPxfOgOGHKkrJ_q56g0H8x-sjKm1mkjND0VAK3H22nwFlGNk5wfTocCb5mKMvTYwsZAv5sh0SACHdbb_9BGftMuqbFdm6wH0wXF-Sq3noF7hc2FeUUauhDfrBq5jTSou4NO3EBwjc0jj3v-yQzPGMCFxq2Q8C9uhat14rGYteYqj5mX3L5JtwHrobePL2R9lcnagNIMa44GUWQ8DVR2urP4KCrDHJf1G5pIfv94uB85I7sbf0nse7VvhYp058I8voNR9_zD1XC5-AODQJ16F484zxQokX1BWJ3gfgd86zJr2O9iKsA",
"token_type": "bearer",
"expires_in": 1209599,
".issued": "Sat, 20 Feb 2016 13:15:10 GMT",
".expires": "Sat, 05 Mar 2016 13:15:10 GMT"
}
定义为:
TBoard
我在标记的行上收到错误:
TBoard = class
field: array[1..5,1..5] of Integer;
function check(const x, y: Integer): Integer;
function addShip(x, y, size, dir: Integer): Integer;
function attack(const x, y: Integer): Integer;
end;
有人知道发生了什么吗? 提前谢谢!
答案 0 :(得分:9)
您只是在case语句中缺少begin和end,所以将函数更改为
function TBoard.attack(const x, y: Integer): Integer;
begin
Result := Self.check(x, y);
case Result of
0:
begin
Self.field[x, y] := 1;
Exit;
end
else Exit;
end;
end;
但是,如果这是您的完整代码,您可以非常简化,您不需要所有这些退出,也不需要案例陈述:
function TBoard.attack(const x, y: Integer): Integer;
begin
Result := Self.check(x, y);
if Result = 0 then
Self.field[x, y] := 1;
end;