[Overview][Resource strings][Constants][Types][Classes][Procedures and functions][Index] Reference for unit 'tiObject' (#tiopf)

TtiObject.CreateNew

Creates a new instance of the class

Declaration

Source position: tiObject.pas line 412

public constructor TtiObject.CreateNew(

  const AOwner: TtiObject;

  const ADatabaseName: string = '';

  const APersistenceLayerName: string = ''

); virtual; overload;

constructor TtiObject.CreateNew(

  const ADatabaseName: string = '';

  const APersistenceLayerName: string = ''

); virtual; overload;

Description

Creates a new instance of the class. It also initialises it's OID with next available value and sets ObjectState to posCreate. It is important to understand the difference between Create and CreateNew.

If you have a customer class TCustomer and do this:

lCustomer := TCustomer.Create;
lCustomer.Name := 'Acme Widget Company';
lCustomer.LastOrderDate := Now;
lCustomer.Save;

Not much will happen, aside from you having a created customer object - it won't be saved to the database.

However, this:

lCustomer := TCustomer.CreateNew;
lCustomer.Name := 'Acme Widget Company';
lCustomer.LastOrderDate := Now;
lCustomer.Save;

will create the customer and save it to the database. Under the hood, CreateNew instantiates the object by calling create, then creates the appropriate OID class and sets its value to the next/appropriate value, then sets the ObjectState of the object to posCreate. This means that the Save method will execute the create visitor for the Customer class.

See also

TtiObject.Create

  

Creates a new instance of the class


Documentation generated on: 2017-08-16