@@ -939,6 +939,7 @@ TExposedMethodImplementation = class(TAbstractExposedMemberImplementation)
939
939
940
940
function VirtualMethodImplementation (): pointer;
941
941
942
+ class function MethodDocStr (const ARttiMethod: TRttiMethod): string;
942
943
class function Methods_Wrapper (const ASelf, AArgs, AKeyWords: PPyObject): PPyObject; static; cdecl;
943
944
944
945
property MethodHandler: TExposedMethodHandler read FMethodHandler write FMethodHandler;
@@ -1138,6 +1139,65 @@ function TExposedMethodImplementation.GetDocString(): string;
1138
1139
Name , FRttiType.Name , NativeInt(Self)]);
1139
1140
end ;
1140
1141
1142
+ class function TExposedMethodImplementation.MethodDocStr
1143
+ (const ARttiMethod: TRttiMethod): string;
1144
+ const
1145
+ METHOD_DOC_STR_PATTERN = ' %s.%s(%s)' ;
1146
+ var
1147
+ LArgsStr: string;
1148
+ LRttiParameter: TRttiParameter;
1149
+ begin
1150
+ if (Length(ARttiMethod.GetParameters) = 0 ) then
1151
+ Exit(String.Empty);
1152
+
1153
+ LArgsStr := String.Empty;
1154
+ for LRttiParameter in ARttiMethod.GetParameters do begin
1155
+ if not LArgsStr.IsEmpty then
1156
+ LArgsStr := LArgsStr + ' , ' ;
1157
+
1158
+ if not Assigned(LRttiParameter.ParamType) then
1159
+ LArgsStr := LArgsStr + LRttiParameter.Name
1160
+ else
1161
+ LArgsStr := LArgsStr + LRttiParameter.Name + ' =' + LRttiParameter.ParamType.Name ;
1162
+ end ;
1163
+
1164
+ Result := String.Format(METHOD_DOC_STR_PATTERN, [
1165
+ ARttiMethod.Parent.Name , ARttiMethod.Name , LArgsStr]);
1166
+
1167
+ if Assigned(ARttiMethod.ReturnType) then
1168
+ Result := Result + ' : ' + ARttiMethod.ReturnType.Name ;
1169
+
1170
+ // Args:
1171
+ // param1: The first parameter.
1172
+ // param2: The second parameter.
1173
+ if Length(ARttiMethod.GetParameters()) > 0 then begin
1174
+ Result := Result + #10 + #10 + ' Args:' + #10 ;
1175
+ for LRttiParameter in ARttiMethod.GetParameters do begin
1176
+ if Assigned(LRttiParameter.ParamType) then
1177
+ Result := Result + String.Format(' %s (%s)' , [LRttiParameter.Name , LRttiParameter.ParamType.Name ])
1178
+ else if TParamFlag.pfVar in LRttiParameter.Flags then
1179
+ Result := Result + String.Format(' %s (%s)' , [LRttiParameter.Name , ' var' ])
1180
+ else if TParamFlag.pfConst in LRttiParameter.Flags then
1181
+ Result := Result + String.Format(' %s (%s)' , [LRttiParameter.Name , ' const' ])
1182
+ else if TParamFlag.pfOut in LRttiParameter.Flags then
1183
+ Result := Result + String.Format(' %s (%s)' , [LRttiParameter.Name , ' out' ]);
1184
+
1185
+ Result := Result + #10 ;
1186
+ end ;
1187
+ end ;
1188
+
1189
+ if Assigned(ARttiMethod.ReturnType) then begin
1190
+ // Returns:
1191
+ // The return value. True for success, False otherwise.
1192
+
1193
+ Result := Result + #10 + ' Returns:' + #10 ;
1194
+ Result := Result + String.Format(' Return type: %s' , [
1195
+ ARttiMethod.ReturnType.Name ]) + #10 ;
1196
+ end ;
1197
+
1198
+ Result := Result + #10 ;
1199
+ end ;
1200
+
1141
1201
function TExposedMethodImplementation.VirtualMethodImplementation (): pointer;
1142
1202
var
1143
1203
LRttiCtx: TRttiContext;
@@ -3400,6 +3460,11 @@ class procedure TPyDelphiObject.ExposeMethods(const AClass: TClass;
3400
3460
LClass := LClass.ClassParent;
3401
3461
end ;
3402
3462
3463
+ // Build the DocStr including method args
3464
+ LExposedMethod.DocString :=
3465
+ AnsiString(TExposedMethodImplementation.MethodDocStr(LRttiMethod))
3466
+ + LExposedMethod.DocString;
3467
+
3403
3468
// Adds the Python method
3404
3469
if LRttiMethod.IsStatic then
3405
3470
APythonType.AddStaticMethodWithKeywords(
0 commit comments