Why does not the compiler shows me the hint H2077 for variable s?
Why does not the compiler shows me the hint H2077 for variable s?
procedure Execute;
var
s: string;
i: Integer;
begin
s := '';
s := 'Foo'; // <-- No hints
s := 'Hello World'; // <-- No hints
i := 0;
i := 2; // [DCC Hint] Project1.dpr(16): H2077 Value assigned to 'i' never used
WriteLn(s, i);
end;
procedure Execute;
var
s: string;
i: Integer;
begin
s := '';
s := 'Foo'; // <-- No hints
s := 'Hello World'; // <-- No hints
i := 0;
i := 2; // [DCC Hint] Project1.dpr(16): H2077 Value assigned to 'i' never used
WriteLn(s, i);
end;
Yes, for variable i I get a hint, but why not for the variable s?
ReplyDeleteI think 'cause the code is calling UStrClr and UStrLAsg and they are procedures and the compiler cannot check this condition.
ReplyDeleteSame with Integer:
procedure TestWithInteger;
procedure MakeZero(var A: Integer);
begin
A := 0;
end;
procedure MakeOne(var A: Integer);
begin
A := 1;
end;
var
I: Integer;
begin
MakeZero(I);
MakeOne(I);
WriteLn(I);
end;
Did you try this with other managed types than string like mentioned in this link: http://stackoverflow.com/questions/5351508/what-are-managed-types-are-they-specific-to-delphi-are-they-specific-to-window/5351597#5351597
ReplyDelete