Hi all,
I would like to add, to a python4delphi module, a getter method which return a 'dict'.
For example:
> import pycnccore1 as pyc
>cnc_core = pyc.CNCCore()
>print(cnc_core.paths)
{'user_path': 'c:\\xyz', 'machine_path': 'd:\\machine_test', and so on}
I don't know how to create a Delphi type to contain the dictionary and convert it to a Python dict as a result of the getter method.
function TPyCNCCore.GetPaths(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
var PathDict: <i_do_not_know>;
PathDict.Append('user_path', Self.UserPathString);
PathDict.Append('machine_path', Self.MachinePathString);
... and so on ...
Result := GetPythonEngine.VariantAsPyObject(PathDict);
end;
class procedure TPyCNCCore.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
with PythonType do
begin
PythonType.AddGetSet('paths', @TPyCNCCore.GetPaths, nil, 'Returns the used paths', nil);
end;
end;
Thanks in advance for your suggestions
Silverio