1

I want to know disposed record by pointer variable.

For example, I have the record like below and the global variables(T, P).

TTest = record
 iA: Integer;
 sA: string;
end;
pTest = ^TTest;

T: pTest;
P: Pointer;

And then call below procedure.

...

procedure TestCreate;  
begin
  New(T);
  T^.iA := 100;
  T^.sA := 'ABCD';

  // 1.
  P := T;

  // 2.
  Dispose(T);

  // 3.
  WriteLn( IntToStr(pTest(P)^.iA) );
  // -> Show the 100
end;

Is there a way I can know with pointer 'P' that if record 'T' has been disposed?

Fabrizio
  • 7,603
  • 6
  • 44
  • 104

1 Answers1

2

There is no way to tell, from just the pointer alone, whether the value pointed to is still valid or not. It is not possible without some additional code to keep track of it somehow.

As a side note, I hope you know that you can work with records without involving pointers at all? For example:

type
  TTest = record
   iA: Integer;
   sA: string;
  end;
var
  T: TTest;
begin   
  T.iA := 100;
  T.sA := 'ABCD';
Matthias B
  • 404
  • 4
  • 11
  • OH! I know. I had not uploaded overall source. I need to use pointer value because different object more than one refer to the pointer. Thank you! – Jung-soo Lee Aug 29 '19 at 00:17