问题描述
我维护一个必须在多个Delphi版本中运行的Delphi组件。 在最近的几个版本中,我注意到行为有所改变。
以下代码在Delphi 10.1中给出警告,并在Delphi 10.2中正常编译:
[dcc32警告] asdf.pas(1179):W1035函数“ TSomeClass.SomeFunc”的返回值可能未定义
function TSomeClass.SomeFunc(objc: TObject; const xD: array of string): integer;
var
s: string;
i: Integer;
begin
try
repeat
s := ReadLn;
// more code here
for i := 0 to High(xD) do
begin
if s = xD[i] then
begin
// Result := 0;
exit;
end;
end;
// more code here
until False;
finally
Result := 0;
end;
end;
以下代码在Delphi 10.2中给出了提示,并在Delphi 10.1中可以正常编译:
[dcc32提示] asdf.pas(1179):H2077从未分配给'TSomeClass.SomeFunc'的值
function TSomeClass.SomeFunc(objc: TObject; const xD: array of string): integer;
var
s: string;
i: Integer;
begin
try
repeat
s := ReadLn;
// more code here
for i := 0 to High(xD) do
begin
if s = xD[i] then
begin
Result := 0;
exit;
end;
end;
// more code here
until False;
finally
Result := 0;
end;
end;
这种行为发生了改变吗?
解决方法
编译器生成的代码的行为没有改变。您的代码将在所有版本的编译器中以相同的方式执行。
但是,提示和警告在10.1中是错误的。这些是由10.2修复的编译器错误。第一个示例不应生成警告W1035。第二个示例应生成提示H2077。