unit
fs_iMyClassRTTI;
interface
uses
Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls, Forms;
type
TMyClass=
class
(TObject)
private
FNewProp:
string
;
FNewProp2:
string
;
public
constructor
Create;
function
Func1(int i):int;
function
Func2(str:TStrings):
boolean
;
public
property
NewProp2:
string
read FNewProp2
write
FNewProp2;
published
property
NewProp:
string
read FNewProp
write
FNewProp;
end
;
implementation
type
TFunctions =
class
(TfsRTTIModule)
private
private
function
CallMethod(Instance: TObject; ClassType: TClass;
const
MethodName:
String
; Caller: TfsMethodHelper): Variant;
function
GetProp(Instance: TObject; ClassType: TClass;
const
PropName:
String
): Variant;
procedure
SetProp(Instance: TObject; ClassType: TClass;
const
PropName:
String
; Value: Variant);
public
constructor
Create(AScript: TfsScript); override;
end
;
function
TMyClass
.
Func1(int i):int;
begin
result:=
0
;
end
;
function
TMyClass
.
Func2(str:TStrings):
boolean
;
begin
result:=
True
;
end
;
function
TFunctions
.
CallMethod(Instance: TObject; ClassType: TClass;
const
MethodName:
String
; Caller: TfsMethodHelper): Variant;
begin
Result :=
0
;
if
ClassType = TMyClass
then
begin
if
MethodName =
'CREATE'
then
Result :=
Integer
(TMyClass
.
Create)
else
if
MethodName =
'FUNC1'
then
Result:= TMyClass(Instance).Func1(Caller
.
Params[
0
]))
else
if
MethodName =
'FUNC2'
then
Result := TMyClass(Instance).Func2(TStrings(
Integer
(Caller
.
Params[
0
])))
end
;
end
;
constructor
TFunctions
.
Create(AScript: TfsScript);
begin
inherited
;
with
AScript
do
begin
with
AddClass(TMyClass,
'TObject'
)
do
begin
AddMethod(
'function Func1(int i):int;'
,CallMethod);
AddMethod(
'function Func2(str:TStrings):boolean;'
,CallMethod);
end
;
end
;
end
;
function
TFunctions
.
GetProp(Instance: TObject; ClassType: TClass;
const
PropName:
String
): Variant;
begin
if
ClassType = TMyClass
then
begin
if
PropName =
'NewProp2'
then
Result := TMyClass(Instance).NewProp2;
end
end
;
procedure
TFunctions
.
SetProp(Instance: TObject; ClassType: TClass;
const
PropName:
String
; Value: Variant);
begin
if
ClassType = TMyClass
then
begin
if
PropName =
'NewProp2'
then
TMyClass(Instance).NewProp2:=Value;
end
end
;
initialization
fsRTTIModules
.
Add(TFunctions);
finalization
fsRTTIModules
.
Remove(TFunctions);