Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- [MVCNameCase(ncLowerCase)]
- [MVCTable('customers')]
- TCustomerWithTransient = class(TMVCActiveRecord)
- private
- [MVCPrimaryKey('id', [foAutoGenerated])]
- fID: Integer;
- [MVCTableField('code', [foTransient])]
- fCode: string;
- [MVCTableField('description')]
- fCompanyName: string;
- [MVCTableField('city', [foTransient])]
- fCity: string;
- public
- property ID: Integer read fID write fID;
- property Code: string read fCode write fCode;
- property CompanyName: string read fCompanyName write fCompanyName;
- property City: string read fCity write fCity;
- end;
- ...
- procedure TMainForm.btnTransientFieldsClick(Sender: TObject);
- var
- lCustomer: TCustomerWithTransient;
- lID: Integer;
- begin
- Log('Transient CRUD test');
- lCustomer := TCustomerWithTransient.Create;
- try
- {
- 'Code' and City will not be persisted because defined as 'transient'
- }
- lCustomer.Code := '1234';
- lCustomer.CompanyName := 'Google Inc.';
- lCustomer.City := 'Montain View, CA';
- lCustomer.Insert;
- lID := lCustomer.ID;
- Log('Just inserted "transient" Customer ' + lID.ToString);
- finally
- lCustomer.Free;
- end;
- lCustomer := TMVCActiveRecord.GetByPK<TCustomerWithTransient>(lID);
- try
- lCustomer.CompanyName := lCustomer.CompanyName + ' changed!';
- lCustomer.Code := 'this code will not be saved';
- lCustomer.Update;
- Log('Just updated Customer ' + lID.ToString);
- finally
- lCustomer.Free;
- end;
- lCustomer := TMVCActiveRecord.GetByPK<TCustomerWithTransient>(lID);
- try
- lCustomer.Delete;
- Log('Just deleted "transient" Customer ' + lID.ToString);
- finally
- lCustomer.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement