You are not logged in.
Pages: 1
Regarding the documentation I'm trying to send the TStringList (dictionary).
TTest = class(TInterfacedObject, ITest)
procedure GetParams(out params: TStrings);
end;
procedure TTest.GetParams(out params: TStrings);
begin
params := TStringlist.create;
params.Values['name'] := 'John';
end;
how to free the params stringlist (do I have to free that list?)
Offline
When called from a service, the out parameter is already allocation.
You don't need to write params := TStringList.Create.
And you don't need to free it: it will be freed by the framework.
Offline
OK, how to deal with stringlist as a part of record?
TVehicle = record
Make: string;
Model: string;
TechnicalDetails: TStrings;
end;
TTest = class(TInterfacedObject, ITest)
procedure GetVehicle(out vehicle: TVehicle);
end;
procedure TTest.GetVehicle(out vehicle: TVehicle);
begin
vehicle.Make := 'volvo';
vehicle.TechnicalDetails := TStringList.Create -> ????
vehicle.TechnicalDetails['Engine'] := 'Diesel';
end;
The framework probably won't create/free that stringlist for me?
Last edited by radexpol (2022-01-30 11:29:34)
Offline
Let me try to answer myself.
TVehicle = record
Make: string;
Model: string;
TechnicalDetails: IKeyValue<string, string>;
end;
TTest = class(TInterfacedObject, ITest)
procedure GetVehicle(out vehicle: TVehicle);
end;
procedure TTest.GetVehicle(out vehicle: TVehicle);
begin
vehicle.Make := 'volvo';
vehicle.TechnicalDetails := Collections.NewKeyValue<string, string>;
vehicle.TechnicalDetails.TryAdd('Engine', 'Diesel');
end;
can I use safely the code like above ?
Offline
The framework probably won't create/free that stringlist for me?
I think the easiest will be:
If you want to use a record, use TStringDynArray instead of TStrings.
Or convert the record TVehicle to a class TVehicle = class(TSynPersistent/TObjectWithID) with published property TechnicalDetails: TStrings. Or have a look at the classes ...AutoCreateFields.
With best regards
Thomas
Offline
How to store key+value in:
/// a dynamic array of UTF-8 encoded strings
TRawUtf8DynArray = array of RawUtf8;
?
Offline
How to store key+value in: ?
TSynDictionary has the functions SaveToJson() and LoadFromJson(). In unit mormot.core.collections you will find Collections.NewKeyValue<TKey, TValue>.
var
list: IKeyValue<Int64, RawUtf8>;
begin
list := Collections.NewKeyValue<Int64, RawUtf8>;
In the example you also have access to other TSynDictionary methods with list.Data.xxx. In the unit test.core.collections you can find an example of how to use it.
With best regards
Thomas
Offline
Or just use a TDocVariantData stored into a variant.
+1 I like DocVariants very much. Whenever you get stuck, a DocVariant comes along from somewhere.
Last edited by tbo (2022-01-30 21:11:42)
Offline
Pages: 1