[Overview][Resource strings][Constants][Types][Classes][Procedures and functions][Index] |
Creates a new instance of the class
Source position: tiObject.pas line 409
public constructor TtiObject.Create; override; |
Creates a new instance of the class. This constructor also sets the ObjectState property to posEmpty. 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.
|
Creates a new instance of the class |