DelphiBasics
New
Procedure
Create a new pointer type variable System unit
1 procedure New(var VariablePointer Pointer-Type);
2 procedure New (var ObjectPointer Object-Pointer; Constructor;
Description
The New procedure comes in two flavours.
 
The older version is an obsolete method of creating objects (you should now call the class constructor instead).
 
The first version allocates storage for a pointer type variable VariablePointer.
 
New is used when the storage is requirement is fixed in size. Use GetMem to dictate the exact storage size allocated.
Related commands
DisposeDispose of storage used by a pointer type variable
FreeMemFree memory storage used by a variable
GetMemGet a specified number of storage bytes
ReallocMemReallocate an existing block of storage
 Download this web site as a Windows program.




 
Example code : Allocate memory for a record, and assign to it
type
  TCustomer = Record
    name : string[20];
    age  : Byte;
  end;

var
  custRecPtr : ^TCustomer;

begin
  // Create a customer record using 'New'
  New(custRecptr);

  // Assign values to it
  custRecPtr.name := 'Her indoors';
  custRecPtr.age  := 55;

  // Now display these values
  ShowMessageFmt('%s is %d',[custRecPtr.name, custRecPtr.age]);

  // Now dispose of this allocated record
  Dispose(custRecPtr);
end;
Show full unit code
  Her indoors is 55
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page