-
Notifications
You must be signed in to change notification settings - Fork 36
HowToReadonlyStoredField
Carlo Barazzetta edited this page Jan 27, 2017
·
1 revision
suppose you have a model Employee with field Name, Surname, Description. The user uploads Name and Surname and the program must fill Description with Name + Surname.
You have to define a rule.
You have to define a model rule in your Kitto project that fires before store.
Example: Code in Employee.yaml
ModelName: Employee
.......
Rules:
EmployeeCalcDescription:
Code in Rules.pas
unit Rules;
.....
type
TEmployeeCalcDescription = class(TKRuleImpl)
public
procedure BeforeAddorUpdate(const ARecord: TKRecord); override;
end;
.....
implementation
......
procedure TEmployeeCalcDescription.BeforeAddorUpdate(const ARecord: TKRecord);
begin
inherited;
ARecord.FieldByName('Description').Value :=
ARecord.FieldByName('Surname').AsString + ' ' +
ARecord.FieldByName('Name').AsString);
end;
You have to write a field rule in your Kitto project that fires at change of Name or Surname.
Example: Code in Employee.yaml
ModelName: Employee
PhysicalName: EMPLOYEE
Fields:
.....
Description: String(200) not null
PhysicalName: DX
IsReadOnly: True
DisplayWidth: 39
Surname: String(50) not null
PhysicalName: SURNAME
IsVisible: False
IsReadOnly: True
Rules:
EmployeeCalcDescription:
Name: String(50) not null
PhysicalName: NAME
IsVisible: False
IsReadOnly: True
Rules:
EmployeeCalcDescription:
Code in Rules.pas
unit Rules;
.....
type
TEmployeeCalcDescription = class(TKRuleImpl)
public
procedure AfterFieldChange(const AField: TKField;
const AOldValue, ANewValue: Variant); override;
end;
.....
implementation
......
procedure TEmployeeCalcDescription.AfterFieldChange(
const AField: TKField; const AOldValue, ANewValue: Variant);
begin
inherited;
AField.ParentRecord.FieldByName('Description').Value :=
AField.ParentRecord.FieldByName('Surname').AsString + ' ' +
AField.ParentRecord.FieldByName('Name').AsString);
end;
- Kitto at a glance
- Getting started
- Setup
-
Basic concepts
- Basic Materials
- Controllers
- Features
- Kitto Enterprise
- Examples
- Developer's guide
- Library reference
- Frequently Asked Questions
- Kitto tips & tricks and how-tos
- Other information