tags:

views:

110

answers:

2

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;
+6  A: 

Use Type-checked pointers ({$T+} directive)

Serg
That is what I needed. Thank you.
soid
+2  A: 

There's an option in Project settings -> Compiler settings exactly for this.

Eugene Mayevski 'EldoS Corp
Thank you. Oops, I should have seen that. It is Project : Options : Compiler : Typed @ operator.
soid