Suppose I have an Entity with a two properties, for example Revenue (boolean) and Amount (Double). I would like to display Amount as positive and store as negative numbers if Revenue is false (i.e. Cost). To achieve this I would write a property Getter and a Setter:
function TMyEntity.GetAmount: Double
begin
if FRevenue then
result := FAmount
else
result := FAmount * -1;
end;
function TMyEntity.SetAmount(AValue: Double);
begin
if FRevenue then
FAmount := AValue
else
FAmount := AValue * -1;
end;
I suppose this should work, but how can I achieve this by scripting so that I do not manually have to update the entity every time I update the model and (re-)create the unit? Is there an example somewhere?
Please ignore the last question. Through some trial and error I managed to solve the issue. I answer it here to create an example that may of use for someone else in the future.
Note the .Modifier := pmNone, pmVar is not allowed for property setter
I then modify the property line in the class as:
procedure OnColumnGenerated(Args: TColumnGeneratedArgs);
begin
if Args.CodeType.Name = 'TMyEntity' then
begin
if Args.Prop.Name = 'Amount' then
begin
Args.Prop.ReadMember := 'GetAmount';
Args.Prop.WriteMember := 'SetAmount';
end;
end;
end;