You are not logged in.
Pages: 1
I would like to pass different record types as a result of procedure. Is that possible, or any suggestion how to deal with it?
type
TVehicleType = (vtBus, vtCar);
type
TCommonAttributes = packed record
wheelCount: integer;
end;
TCar = packed record
common: TCommonAttributes;
power: integer;
end;
TBus = packed record
common: TCommonAttributes;
seats: integer;
end;
type
TVehicles = class(TInterfacedObject,IVehicles)
procedure GetVehicle(const VehicleType: TVehicleType; out outputVehicle: pointer); --> pointer is not accepted by mORMot
end;
implementation
procedure TVehicles.GetVehicle(const VehicleType: TVehicleType; out outputVehicle: pointer);
begin
case VehicleType of
vtBus: begin
var busInfo: TBus;
busInfo.common.wheelCount := 6;
busInfo.seats := 40;
outputVehicle := @busInfo;
end;
end;
I hope I won't have to create the separate methods for all vehicle kinds such as:
procedure GetBus(out outputVehicle: TBus);
Any smart solution for such issue?
Offline
You could use:
1. Several "out" parameters, only one actually with data at output. In mORMot 2, the default values won't be serialized, so unused "out" parameters would not add anything huge at the transmission level.
2. Using a TDocVariantData and a "out variant" parameter.
3. Using RecordSaveJson() and a "out RawJson" parameter.
4. Using RecordSaveBinary() and a "out RawByteString" parameter (if a lot of blob content within).
5. A method-based service.
6. ... ?
But I would not go into this direction, because it may became a very complex API, non self-documented any more.
Any duplicated methods, one per kind of result, seems better for me as API definition.
Offline
Pages: 1