home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap16 / pointer5 / pointer5.dos < prev    next >
Encoding:
Text File  |  1995-03-21  |  1.2 KB  |  27 lines

  1. program Pointer5;
  2. uses
  3.   Strings;
  4.   
  5. var
  6.   A: Pointer;
  7.   B: PChar;
  8. begin                     { Open program                   }
  9.   HeapLimit := 0;         { "Turn off" Pascal sub-allocator}
  10.   A := Ptr(DSeg, 0);      { A "fake" pointer to nothing,   }
  11.   B := Ptr($45FF, 16);    { There is no memory allocation! }
  12.   A := nil;               { Set pointer to nil             }
  13.   B := nil;               { Set pointer to nil             }
  14.   New(A);                 { Pointer will STILL equals nil! }
  15.   Dispose(A);             { Does nothing                   }
  16.   GetMem(A, 100);         { Allocate a hundred bytes       }
  17.   GetMem(B, 100);         { Allocate a hundred bytes       }
  18.   StrCopy(B, 'Test data');{ Use the allocation             }
  19.   FreeMem(A, 100);        { Deallocate 100 bytes           }
  20.   A := nil;               { Set pointer to nil             }
  21.   FreeMem(B, 100);        { Deallocate 100 bytes           }
  22.   asm                     { Set pointer to nil in ASM block}
  23.     mov word ptr B, 0;    { Zero out offset                }
  24.     mov word ptr B + 2, 0;{ Zero out segment               }
  25.   end;                    { Close ASM block                }
  26. end.                      { Close program                  }
  27.