Hi, Wagner. I am testing last changes on version 7.4
Type of proprties is not shown if I use DefineClassByRTTI.
Please check.
I have my new solution of this problem. But my solution some big and not optimal.
My solution also show result type of functions.
May by this solution help You. This is difference file. I may send You changed 2 files.
In my solution i store RTTI information for types of properties and methods.
TMSScripter/source/core/atScript.pas | 27 +-
TMSScripter/source/ide/fLibraryBrowser.pas | 10 +-
diff --git a/TMSScripter/source/core/atScript.pas b/TMSScripter/source/core/atScript.pas
index c1d75b8..fadc7b3 100644
--- a/TMSScripter/source/core/atScript.pas
+++ b/TMSScripter/source/core/atScript.pas
@@ -4491,6 +4491,7 @@ type
FPropertyClass: TClass;
FPropertyClassName: string;
FPropInfo: PPropInfo; // for use with RTTI
+ FDataTypeInfo: TRttiType; // RTTI information for type of property
{$IFDEF NEWSTACK}
FRttiProp: TRttiProperty;
{$ENDIF}
@@ -4601,6 +4602,7 @@ type
property LibContext: string read FLibContext;
property Writeable: boolean read GetWriteable;
+ property DataTypeInfo: TRttiType read FDataTypeInfo write FDataTypeInfo;
end;
/// <summary>
@@ -4658,6 +4660,7 @@ type
FDefArgCount: integer;
FResultClassName: string;
FLibContext: string;
+ FResultTypeInfo: TRttiType; // RTTI information for type of result
procedure SetArgDefs(const Value: TatDataDefs);
// variable arguments bit mask (just initial 32 arguments will be checked in compile time!!!)
procedure AdjustArgDefsCount;
@@ -4796,6 +4799,7 @@ type
/// "namespace" for the method.
/// </summary>
property LibContext: string read FLibContext;
+ property ResultTypeInfo: TRttiType read FResultTypeInfo write FResultTypeInfo;
end;
/// <summary>
@@ -8043,6 +8047,7 @@ var
Pars: TArray<TRttiParameter>;
scriptMethod: TatMethod;
c: integer;
+ DefinedProp:TatProperty;
begin
Context := TRttiContext.Create;
try
@@ -8050,10 +8055,13 @@ begin
atClass := DefineRecord(ATypeInfo);
for field in rtype.GetFields do
- atClass.DefineProp(field.Name, ScrTypeKind(field.FieldType),
+ begin
+ DefinedProp:=atClass.DefineProp(field.Name, ScrTypeKind(field.FieldType),
GenericRecordFieldGetterMachineProc, GenericRecordFieldSetterMachineProc,
- ScrClassType(field.FieldType)).FPropertyClassName := ScrClassName(field.FieldType);
-
+ ScrClassType(field.FieldType));
+ DefinedProp.FPropertyClassName := ScrClassName(field.FieldType);
+ DefinedProp.FDataTypeInfo := field.FieldType;
+ end;
Result := atClass;
// define methods
@@ -8087,6 +8095,7 @@ begin
scriptMethod := Result.DefineMethod(method.Name, Length(Pars), TypeKind, regClass,
GenericRecordMethodMachineProc, method.IsClassMethod or method.IsConstructor);
scriptMethod.FResultClassName := regClassName;
+ scriptMethod.FResultTypeInfo := method.ReturnType;
// if method.IsConstructor then
// coverloaded := True;
@@ -9567,6 +9576,7 @@ var
{$IFDEF DELPHIXE2_LVL}
NewProp: TatProperty;
{$ENDIF}
+ DefinedProp:TatProperty;
begin
Inc(FRegLevel);
try
@@ -9653,6 +9663,7 @@ begin
scriptMethod := Result.DefineMethod(method.Name, Length(Pars), TypeKind, regClass,
FScripter.GenericMethodMachineProc, method.IsClassMethod or method.IsConstructor);
scriptMethod.FResultClassName := regClassName;
+ scriptMethod.FResultTypeInfo := method.ReturnType;
if method.IsConstructor then
coverloaded := True;
@@ -9704,8 +9715,12 @@ begin
Setter := nil;
regClass := FScripter.ScrClassType(prop.PropertyType);
if (Options.Redefine <> roInclude) or (Result.PropertyByName(prop.Name) = nil) then
- Result.DefineProp(prop.Name, FScripter.ScrTypeKind(prop.PropertyType), Getter, Setter,
- regClass).FPropertyClassName := FScripter.ScrClassName(prop.PropertyType);
+ begin
+ DefinedProp := Result.DefineProp(prop.Name, FScripter.ScrTypeKind(prop.PropertyType), Getter, Setter,
+ regClass);
+ DefinedProp.FPropertyClassName := FScripter.ScrClassName(prop.PropertyType);
+ DefinedProp.FDataTypeInfo := prop.PropertyType;
+ end;
if prop.PropertyType <> nil then
begin
@@ -10619,6 +10634,7 @@ begin
Setter := TatProperty(Source).Setter;
PropertyClass := TatProperty(Source).PropertyClass;
PropInfo := TatProperty(Source).PropInfo;
+ DataTypeInfo := TatProperty(Source).DataTypeInfo;
{$IFDEF NEWSTACK}
FRttiProp := TatProperty(Source).FRttiProp;
{$ENDIF}
@@ -11023,6 +11039,7 @@ begin
Name := TatMethod(Source).Name;
Proc := TatMethod(Source).Proc;
ResultDataType := TatMethod(Source).ResultDataType;
+ ResultTypeInfo := TatMethod(Source).ResultTypeInfo;
ArgCount := TatMethod(Source).ArgCount;
DefArgCount := TatMethod(Source).DefArgCount;
Code := TatMethod(Source).Code;
diff --git a/TMSScripter/source/ide/fLibraryBrowser.pas b/TMSScripter/source/ide/fLibraryBrowser.pas
index 0187c2d..48095e4 100644
--- a/TMSScripter/source/ide/fLibraryBrowser.pas
+++ b/TMSScripter/source/ide/fLibraryBrowser.pas
@@ -7,7 +7,7 @@ interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, ComCtrls,
- atScript, IDEMain, StdCtrls, ImgList, Menus;
+ atScript, IDEMain, StdCtrls, ImgList, Menus, System.ImageList;
type
TAcceptLibraryEvent = procedure(Sender: TObject; const LibName: string; var Accept: boolean) of object;
@@ -196,6 +196,10 @@ begin
else
MethodCaption := Format('%s(%s)', [AMethod.Name, MethodCaption]);
+ // for functions show result type
+ if assigned(AMethod.ResultTypeInfo) then
+ MethodCaption := MethodCaption + ':' + AMethod.ResultTypeInfo.Name;
+ //
// if AMethod.IsClassMethod then
// MethodCaption := 'class ' + MethodCaption;
@@ -240,7 +244,9 @@ begin
PropCaption := PropCaption + ': ' + AProp.PropertyClass.ClassName;
else
if (AProp.PropInfo <> nil) and (AProp.PropInfo^.PropType <> nil) then
- PropCaption := PropCaption + ': ' + TypeInfoName(AProp.PropInfo^.PropType^);
+ PropCaption := PropCaption + ': ' + TypeInfoName(AProp.PropInfo^.PropType^)
+ else
+ if assigned(AProp.DataTypeInfo) then PropCaption := PropCaption + ': ' + AProp.DataTypeInfo.Name;
end;
PropNode := FTree.Items.AddChildObject(ParentNode, PropCaption, AProp);