The following code does not generate a compiler warning in D6. Can I make it warn me about pointing ps at an integer when I have told it that ps points to a string?
procedure Test;
var
i: integer;
s, m: string;
ps: ^string;
begin
s := 'Test message';
ps := @s;
m := ps^;
MessageDlg(m, mtInformation, [mbOK], 0); // This displays 'Test message'.
ps := @i; // I would like a warning here.
m := ps^;
MessageDlg(m, mtInformation, [mbOK], 0); // This might display garbage.
end;
Use Type-checked pointers ({$T+} directive)
There's an option in Project settings -> Compiler settings exactly for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With