Property expressions
In Object Pascal a property is an exposed value that is linked to a field or a method (getter or setter). This is the traditional way of exposing a value property, where the consumer of the property is abstracted from the reader and writer logic. The consumer does not explicitly know how the object provides the value.
Quartex Pascal has full support for the older paradigm but introduces a technique called "property expressions". It basically allows you to program reader and writer logic as a part of the declaration itself. This is completely unheard of under traditional Object Pascal, but common in other languages like C# or Swift.
In classical Object Pascal you could write something like this:
Type
TMyObject = Class( .. )
private
fSubObj: TNameData;
protected
function GetFirstName: String;
procedure SetFirstName(const Value: String);
published
Property FirstName: String read GetFirstName write SetFirstName;
end;
function TMyObject.getFirstName: String;
begin
result := fSubObj.FirstName;
end;
procedure TMyObject.setFirstName(const Value: String);
begin
fSubObj.FirstName:=Value;
end;
Using Quartex Pascal you can omit the GetFirstName() and SetFirstName() methods and just implement the logic as-hoc:
property FirstName: string read ( fSubObject.FirstName ) write ( fSubObject.FirstName := Value );
Property expressions is especially handy for classes with child objects. If a class exposes sub objects (object lists) you traditionally had to write a lot of the same code over and over again, wrapping already existing code in a list object -which for complex class hierarchies reduces execution speed with cause unnecessary bloat. This has changed for the better in products like Delphi with the introduction of generics, but you still have to isolate reader and writer logic in distinct class members. Under Quartex Pascal this is elegantly achieved using arrays:
TMyClass = class
private
FList : array of TElement;
public
property Items[i: Integer] : TElement read (FList[i]) write (FList[i]); default;
property Count : Integer read ( FList.Length );
end;
The technique greatly simplifies number conversion, which can in most cases be done directly in the declaration:
TMyAngle = record
private
fAngle : Float;
public
property Radians : float read fAngle write fAngle;
property Degrees : float read ( RadToDeg(fAngle) ) write ( fAngle := DegToRad(Value) );
end;