forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
propertiesEngine.pas
1337 lines (1226 loc) · 37.1 KB
/
propertiesEngine.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit propertiesEngine;
{$I 'sDef.inc'}
{$I PHP.inc}
interface
uses
{$IFDEF typelib} System.ShareMem, {$ENDIF}
SysUtils, WinAPI.Windows,
Dialogs, Forms, Graphics, Classes, Controls, StdCtrls, TypInfo, Variants,
mainLCL, RTTI, ZendApi, UnitClass, php4delphi, ZENDTypes
;
function setProperty(id: integer; prop: string; Value: variant): boolean;
function getProperty(id: integer; prop: string): variant;
function existProperty(id: integer; prop: string): boolean;
function ValueFromVariant(V: Variant; Kind: TTypeKind): TValue;
function VariantFromValue(v: TValue): Variant;
function existMethod( id: integer; method: string ): boolean;
function hasRType( id: integer; method: string ): boolean;
function existMethodClass( classname: string; method: string ): boolean;
function callMethod(id: integer; method: string; p: array of TValue): TValue;
procedure listMethod( id: integer; arr1: PWSDate );
procedure listMethodfClass( classname: string; arr2: PWSDate; arr1: PWSDate );
function evt_params(classname: string; propname: string): String; overload;
function evt_params(id: integer; propname: string): String; overload;
procedure evt_param_names(classname: string; propname: string; arr1: PWSDate);
procedure evt_param_types(classname: string; propname: string; arr1: PWSDate);
function getProperties(id: integer; tktype: integer): string;
function getPropertiesfClass(classname: string; tktype: integer): string;
function isStrInArray(s: string; a: TWSDate): Boolean; overload;
procedure getPropertiesfClassArr(classname: string; tktype: integer; arr1: PWSDate; arr2: PWSDate);
function getPropReadable(classname: string; propname: string): Boolean;
function getPropWritable(classname: string; propname: string): Boolean;
function getPropertyType(id: integer; prop: string): integer;
function getMethodParams(id: integer; method: string): System.TArray<TRttiParameter>;
procedure getMethodParamsfClass(classname: string; method: string; arr1: PWSDate; arr2: PWSDate);
function getMethodParamss(classname: string; method: string): String;
procedure get_all_classes(arr: PWSDate);
procedure get_all_classes_u(arr: PWSDate);
procedure RegisterClassesA(const AClasses: array of TPersistentClass);
procedure RegisterClassA(AClass: TPersistentClass);
procedure RegisterClassAliasA(AClass: TPersistentClass; Alias: string);
procedure RegisterClassAliasesA(AClass: TPersistentClass; Classes: array of string);
function GetConstructor(rType: TRttiType) : TRttiMethod;
function LoadRTL(RTLPath: String): Boolean;
function RTLLoaded(RTLName: String): Boolean;
procedure getEnumPropValues(classname, prop: string; arr1, arr2: PWSDate);
var Regs, TLLoads, BPLoads, Aliases, AliasesKeys: TWSDate;
implementation
type
FindType = function(ClassName: string): TRttiType;
LibModuleListAddres = function(): PLibModule;
//var uc: TUnitClass;
{
function gui_set_event(id: integer; value: string): Boolean;
var hobj: TObject;
begin
Result := False;
hobj := TObject(id);
if Assigned(hobj) then
Result := HEventObj.EAdd(hobj, 'OnKeyPress',
procedure(Base: TEventObject; Params: TArray<TValue>)
begin
//Inc(Params[0].AsObject.ClassName, Base.EventName);
end);
end;}
function RTLLoaded(RTLName: string): Boolean;
var RTL: String;
begin
RTL := ExtractFileName(RTLName);
Result := isStrInArray(RTL, TLLoads) or isStrInArray(RTL, BPLoads);
end;
function LoadTypeLib(LibraryName: string) : Boolean;
var
GetLibM: LibModuleListAddres;
DllHandle: THandle;
begin
Result := True;
try
if not isStrInArray(LibraryName, TLLoads) then
begin
DllHandle := LoadLibrary(PWideChar(LibraryName));
SetLength(TLLoads, Length(TLLoads)+1);
TLLoads[High(TLLoads)] := ExtractFileName(LibraryName);
if( DllHandle = 0 ) or ( DllHandle = null ) then
begin
Result := False;
Exit;
end;
Pointer(@GetLibM) := getprocaddress(DllHandle, 'LibModuleListAddres');
RegisterModule(GetLibM());
end;
except
on E: Exception do begin
Result := False;
Exit;
end;
end;
end;
function LoadTypePackage(PackageName: string) : Boolean;
var BPLHandle: THandle;
begin
Result := True;
try
if not isStrInArray(PackageName, BPLoads) then
begin
BPLHandle := LoadPackage(PackageName);
SetLength(BPLoads, Length(BPLoads)+1);
BPLoads[High(BPLoads)] := ExtractFileName(PackageName);
if( BPLHandle = 0 ) or ( BPLHandle = null ) then
begin
Result := False;
Exit;
end;
end;
except
on E: Exception do begin
ShowMessage( E.ClassName + ': ' + E.Message );
Result := False;
Exit;
end;
end;
end;
function LoadRTL(RTLPath: string): Boolean;
begin
Result := False;
if RTLPath.EndsWith('.bpl', True) then
Result := LoadTypePackage(RTLPath)
else if RTLPath.EndsWith('.dll', True) then
Result := LoadTypeLib(RTLPath);
end;
function GetConstructor(rType: TRttiType) : TRttiMethod;
var
MaxParams: integer;
Methods: TArray<TRttiMethod>;
Method: TRttiMethod;
Params: TArray<TRttiParameter>;
begin
Methods := rType.GetMethods('Create');
MaxParams := 0;
for Method in Methods do begin
Params := Method.GetParameters();
if (Length(Params) > MaxParams) then begin
Result := Method;
MaxParams := Length(Params);
end;
end;
end;
procedure RegisterClassesA(const AClasses: array of TPersistentClass);
var
I: Integer;
begin
for I := Low(AClasses) to High(AClasses) do begin
RegisterClass(AClasses[I]);
SetLength(Regs, Length(Regs)+1);
Regs[High(Regs)] := AClasses[I].ClassName;
end;
end;
procedure RegisterClassA(AClass: TPersistentClass);
begin
RegisterClass(AClass);
SetLength(Regs, Length(Regs)+1);
Regs[High(Regs)] := AClass.ClassName;
end;
procedure RegisterClassAliasA(AClass: TPersistentClass; Alias: string);
begin
RegisterClassAlias(AClass, Alias);
SetLength(AliasesKeys, Length(AliasesKeys)+1);
AliasesKeys[High(AliasesKeys)] := Alias;
SetLength(Aliases, Length(Aliases)+1);
Aliases[High(Aliases)] := AClass.UnitName + '.' + AClass.ClassName;
end;
procedure RegisterClassAliasesA(AClass: TPersistentClass; Classes: array of string);
var
I: Integer;
begin
for I := Low(Classes) to High(Classes) do begin
RegisterClassAliasA(AClass, Classes[I]);
end;
end;
procedure get_all_classes(arr: PWSDate);
var //x: TUnitType;
s: String;
I, b: integer;
begin
SetLength(arr^, 0);
for s in Regs do
begin
SetLength(arr^, Length(arr^)+1);
b := -1;
for I := 0 to Length(AliasesKeys)-1 do
if AliasesKeys[I] = s then
b := I;
if b > -1 then
begin
arr^[High(arr^)] := Aliases[b];
end
else
begin
arr^[High(arr^)] := s;
end;
end;
end;
procedure get_all_classes_u(arr: PWSDate);
var x: TUnitType;
begin
for x in UnitClass.TClassUnits.GetList do
begin
SetLength(arr^, Length(arr^)+1);
arr^[High(arr^)] := x.lowerName2;
end;
end;
function evt_params(classname: string; propname: string): String; overload;
type
PParamFlags = ^TParamFlags;
var
TypeData: PTypeData;
Ptr: PByte;
b: integer;
Flags: TParamFlags;
ParamName: string;
TypeInfo: PTypeInfo;
begin
if not ( Assigned( GetClass(classname) ) ) then begin
Result := '!';
Exit;
end;
if not ( Assigned( GetPropInfo( GetClass(classname), propname) ) ) then begin
Result := '!';
Exit;
end;
if not ( Assigned(GetPropInfo( GetClass(classname), propname).PropType) ) then begin
Result := '!';
Exit;
end;
TypeInfo := GetPropInfo( GetClass(classname), propname)^.PropType^;
Result := '';
ParamName := '';
if not Assigned(TypeInfo) or (TypeInfo^.Kind <> tkMethod) then Exit;
TypeData := GetTypeData(TypeInfo);
if not Assigned(TypeData) then Exit;
Ptr := PByte(@TypeData^.ParamList);
if TypeData^.ParamCount > 0 then
begin
for b := 0 to TypeData^.ParamCount-1 do
begin
if (b > 0) and (TypeData^.ParamCount > 1) then Result := Result + ', ';
Flags := PParamFlags(Ptr)^;
ParamName := '$';
Inc(Ptr, SizeOf(TParamFlags));
if pfVar in Flags then Result := Result;
if pfConst in Flags then Result := Result + 'constant ';
if pfArray in Flags then Result := Result + 'array ';
if pfOut in Flags then Result := Result + '&';
if pfAddress in Flags then ParamName := '&$';
ParamName := ParamName + String(PShortString(Ptr)^);
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
if Length(PShortString(Ptr)^) > 0 then Result := Result +
String(PShortString(Ptr)^);
Result := Result + ' ' + ParamName;
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
end;
end
else
begin
Result := 'void';
end;
end;
function evt_params(id: integer; propname: string): String; overload;
type
PParamFlags = ^TParamFlags;
var
TypeData: PTypeData;
Ptr: PByte;
b: integer;
Flags: TParamFlags;
ParamName: string;
TypeInfo: PTypeInfo;
begin
if not ( Assigned( TObject(id) ) ) then begin
Result := '!';
Exit;
end;
if not ( Assigned( GetPropInfo(TObject(id), propname) ) ) then begin
Result := '!';
Exit;
end;
TypeInfo := GetPropInfo(TObject(id), propname)^.PropType^;
Result := '';
ParamName := '';
if not Assigned(TypeInfo) or (TypeInfo^.Kind <> tkMethod) then Exit;
TypeData := GetTypeData(TypeInfo);
if not Assigned(TypeData) then Exit;
Ptr := PByte(@TypeData^.ParamList);
try
if TypeData^.ParamCount > 0 then
begin
for b := 0 to TypeData^.ParamCount-1 do
begin
if (b > 0) and (TypeData^.ParamCount > 1) then Result := Result + ', ';
Flags := PParamFlags(Ptr)^;
ParamName := '$';
Inc(Ptr, SizeOf(TParamFlags));
if pfVar in Flags then Result := Result;
if pfConst in Flags then Result := Result + 'constant ';
if pfArray in Flags then Result := Result + 'array ';
if pfOut in Flags then Result := Result + '&';
if pfAddress in Flags then ParamName := '&$';
ParamName := ParamName + String(PShortString(Ptr)^);
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
if Length(PShortString(Ptr)^) > 0 then Result := Result +
String(PShortString(Ptr)^);
Result := Result + ' ' + ParamName;
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
end;
end
else
begin
Result := 'void';
end;
except
on E: exception do
Result := '!';
end;
end;
procedure evt_param_names(classname: string; propname: string; arr1: PWSDate);
type
PParamFlags = ^TParamFlags;
var
TypeData: PTypeData;
Ptr: PByte;
B: Byte;
Flags: TParamFlags;
TypeInfo: PTypeInfo;
Result: string;
begin
SetLength(arr1^, 0);
if( Assigned( GetClass( classname ) ) ) then
TypeInfo := GetPropInfo( GetClass( classname ), propname)^.PropType^;
if not Assigned(TypeInfo) or (TypeInfo^.Kind <> tkMethod) then Exit;
TypeData := GetTypeData(TypeInfo);
Ptr := PByte(@TypeData^.ParamList);
if TypeData^.ParamCount > 0 then
begin
for b := 0 to TypeData^.ParamCount-1 do
begin
SetLength(arr1^, Length(arr1^) + 1);
Result := '';
Flags := PParamFlags(Ptr)^;
Inc(Ptr, SizeOf(TParamFlags));
if pfConst in Flags then Result := Result + 'constant ';
if pfArray in Flags then Result := Result + 'array of ';
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
if Length(PShortString(Ptr)^) > 0 then Result := Result +
String(PShortString(Ptr)^);
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
arr1^[High(arr1^)] := Result;
end;
end;
end;
procedure evt_param_types(classname: string; propname: string; arr1: PWSDate);
type
PParamFlags = ^TParamFlags;
var
TypeData: PTypeData;
Ptr: PByte;
B: Byte;
TypeInfo: PTypeInfo;
S: string;
begin
SetLength(arr1^, 0);
if( Assigned( GetClass( classname ) ) ) then
TypeInfo := GetPropInfo( GetClass( classname ), propname)^.PropType^;
if not Assigned(TypeInfo) or (TypeInfo^.Kind <> tkMethod) then Exit;
TypeData := GetTypeData(TypeInfo);
Ptr := PByte(@TypeData^.ParamList);
if TypeData^.ParamCount > 0 then
begin
for b := 0 to TypeData^.ParamCount-1 do
begin
Inc(Ptr, SizeOf(TParamFlags));
SetLength(arr1^, Length(arr1^) + 1);
S := String(PShortString(Ptr)^);
if S = 'Sender' then
arr1^[High(arr1^)] := '$self'
else
arr1^[High(arr1^)] := '$' + LowerCase(S);
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
Inc(Ptr, 1 + Length(PShortString(Ptr)^));
end;
end;
end;
function hasRType( id: integer; method: string ): boolean;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
c : TObject;
begin
Result := False;
ctx := TRttiContext.Create;
c := TObject(integer(id));
lType:=ctx.GetType(c.ClassInfo);
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned( lMethod.ReturnType ) then
if lMethod.ReturnType.TypeKind <> tkUnknown then
begin
Result := True;
end;
end;
finally
if Assigned(lType) then
begin
lType.Free;
if Assigned(lMethod) then
lMethod.Free;
end;
ctx.Free;
end;
end;
function existMethod( id: integer; method: string ): boolean;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
c : TObject;
begin
Result := False;
ctx := TRttiContext.Create;
c := TObject(integer(id));
lType:=ctx.GetType(c.ClassInfo);
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
begin
Result := True;
end;
end;
finally
if Assigned(lType) then
begin
lType.Free;
if Assigned(lMethod) then
lMethod.Free;
end;
ctx.Free;
end;
end;
function existMethodClass( classname: string; method: string ): boolean;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
begin
Result := False;
ctx := TRttiContext.Create;
if Assigned(GetClass(classname)) then
lType:=ctx.GetType( GetClass(classname) );
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
begin
Result := True;
end
end;
finally
if Assigned(lType) then
begin
lType.Free;
if Assigned(lMethod) then
lMethod.Free;
end;
ctx.Free;
end;
end;
procedure listMethodfClass( classname: string; arr2: PWSDate; arr1: PWSDate );
var
ctx : TRttiContext;
lType : TRttiType;
method : TRttiMethod;
apr : System.TArray<Rtti.TRttiParameter>;
param : TRttiParameter;
params : string;
I,L : Byte;
isesc: boolean;
begin
ctx := TRttiContext.Create;
SetLength(arr1^, 0);
SetLength(arr2^, 0);
if not Assigned( GetClass(classname) ) then EXIT;
lType:=ctx.GetType( GetClass(classname) );
if Assigned(lType) then
begin
try
for method in lType.GetMethods() do
begin
if method = nil then Exit;
if ( ( not isStrInArray(method.Name, arr2^)) and ( not method.Name.IsEmpty ) )
then
begin
apr := method.GetParameters;
SetLength(arr1^, Length(arr1^)+1);
SetLength(arr2^, Length(arr2^)+1);
arr2^[High(arr2^)] := method.Name;
if not Assigned(apr) then begin
arr1^[High(arr1^)] := '( void )';
continue;
end;
if length(apr) > 0 then
begin
try
params := '( ';
I := 0;
L := Length(apr) - 1;
for param in apr do
begin
if param = nil then begin
exit;
end;
if param.ParamType = nil then
begin
isesc := True;
break;
end else isesc := False;
params := params + param.ParamType.ToString;
if param.Flags * [pfVar, pfOut] <> [] then
params := params + ' &'
else
params := params + ' ';
params := params + param.Name;
if I < L then
params := params + ', ';
I := I + 1;
end;
params := params + ' )';
if isesc then begin
arr1^[High(arr1^)] := '( void )';
continue;
end;
arr1^[High(arr1^)] := params;
except
on E: exception do
begin
ShowMessage('Very bad error' + #10 + #13 +
'Method Name:' + method.Name + #10 + #13 +
'Method Kind:' + inttostr(integer(method.MethodKind)) +#10 + #13
+ 'Method Visibility:' + inttostr(integer(method.Visibility)) +#10 + #13
+ 'Has Extended Info:' + BoolToStr(method.HasExtendedInfo,true)+#10+ #13
+ 'Is Static:' + BoolToStr(method.IsStatic,true)+#10+#13
+ 'Dispatch Kind:' + inttostr(integer(method.DispatchKind)) +#10 + #13
+ 'Is Class Method:' + BoolToStr(method.IsClassMethod,true)+#10+#13
+ 'CallConv:' + inttostr(integer(method.CallingConvention))+#10+#13
);
ShowMessage( E.Message );
SetLength(arr2^, Length(arr2^)-1);
SetLength(arr1^, Length(arr1^)-1);
end;
end;
end else
arr1^[High(arr1^)] := '( void )';
end;
end;
except
on E: exception do
begin
ShowMessage( E.Message );
SetLength(arr2^, Length(arr2^)-1);
SetLength(arr1^, Length(arr1^)-1);
end;
end;
end;
ctx.Free;
end;
procedure listMethod( id: integer; arr1: PWSDate );
var
ctx : TRttiContext;
lType : TRttiType;
c : TObject;
method : TRttiMethod;
begin
ctx := TRttiContext.Create;
SetLength(arr1^, 0);
c := TObject(integer(id));
lType:=ctx.GetType(c.ClassInfo);
try
if Assigned(lType) then
begin
for method in lType.GetMethods() do
if ( ( not isStrInArray(method.Name, arr1^)) and ( not method.Name.IsEmpty ) ) then
begin
SetLength(arr1^, Length(arr1^)+1);
arr1^[High(arr1^)] := method.Name;
end;
end
else
begin
SetLength(arr1^, 1);
arr1^[0] := '';
end;
finally
if Assigned(lType) then
lType.Free;
ctx.Free;
end;
end;
function VariantFromValue(v: TValue): Variant;
begin
case v.Kind of
tkInteger:
Result := v.AsInteger;
tkEnumeration:
Result := zend_ustr( v.ToString );
tkInt64:
Result := v.AsInt64;
tkWChar:
Result := v.AsType<WideChar>;
tkChar:
Result := v.AsType<AnsiChar>;
tkFloat:
Result := v.AsExtended;
tkString:
Result := String(v.AsType<ShortString>);
tkUString:
Result := v.AsType<UTF8String>;
tkClass:
Result := integer( v.AsObject );
tkPointer:
Result := integer( v.AsType<Pointer> );
tkAnsiString:
Result := v.AsType<AnsiString>;
tkWString:
Result := v.AsType<WideString>;
tkVariant:
Result := v.AsVariant;
end;
end;
function ValueFromVariant(V: Variant; Kind: TTypeKind): TValue;
begin
if VarType(V) = varNull then
Result := Result.Empty;
case Kind of
tkInteger:
Result := Result.From<integer>( integer(V) );
tkInt64:
Result := Result.From<int64>( Int64(V) );
tkWChar:
Result := Result.From<WideChar>( WideString(zend_ustr(V))[1] );
tkAnsiChar:
Result := Result.From<AnsiChar>( AnsiString(zend_ustr(V))[1] );
tkFloat:
Result := Result.From<Extended>( Extended(V) );
tkString:
Result := Result.From<ShortString>( ShortString(V) );
tkClass:
Result := Result.From<TObject>( TObject( integer( V ) ) );
tkUString:
Result := Result.From<Utf8String>( zend_ustr(V) );
tkPointer:
Result := Pointer( integer( V ) );
tkAnsiString:
Result := Result.From<AnsiString>( AnsiString(zend_ustr(V)) );
tkWString:
Result := Result.From<WideString>( WideString(zend_ustr(V)) );
tkEnumeration:
Result := Result.From<String>( zend_ustr(V) );
tkVariant:
Result := Result.FromVariant(V)
end;
end;
function callMethod(id: integer; method: string; p: array of TValue): TValue;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
c : TObject;
begin
Result := TValue.Empty;
ctx := TRttiContext.Create;
c := TObject(integer(id));
lType:=ctx.GetType(c.ClassInfo);
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
begin
Result := lMethod.Invoke(c, p);
end;
end;
finally
if Assigned(lType) then
begin
lType.Free;
if Assigned(lMethod) then
lMethod.Free;
end;
ctx.Free;
end;
end;
function getMethodParams(id: integer; method: string): System.TArray<TRttiParameter>;
label x1;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
c : TObject;
begin
ctx := TRttiContext.Create;
c := TObject(integer(id));
if not Assigned(c) then goto x1;
lType:=ctx.GetType(c.ClassInfo);
if not Assigned(lType) then goto x1;
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
Result := lMethod.GetParameters;
lType.Free;
end;
x1:
ctx.Free;
end;
procedure getMethodParamsfClass(classname: string; method: string; arr1: PWSDate; arr2: PWSDate);
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
x : TRttiParameter;
params : TArray<TRttiParameter>;
begin
ctx := TRttiContext.Create;
SetLength(arr1^, 0);
SetLength(arr2^, 0);
if( Assigned(GetClass(classname)) ) then
lType:=ctx.GetType(GetClass(classname));
if not Assigned(lType) then Exit;
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
if not lMethod.IsConstructor then
begin
params := lMethod.GetParameters;
if not Assigned( params ) then Exit;
for x in params do
begin
if not Assigned(x) then Exit;
if (not x.Name.IsEmpty) then
begin
SetLength(arr1^, Length(arr1^)+1);
arr1^[High(arr1^)] := x.Name;
SetLength(arr2^, Length(arr2^)+1);
arr2^[High(arr2^)] := x.ParamType.ToString();
end;
end;
end;
end;
finally
ctx.Free();
end;
end;
function getMethodParamss(classname: string; method: string): String;
var
ctx : TRttiContext;
lType : TRttiType;
lMethod : TRttiMethod;
b : integer;
x : Rtti.TRttiParameter;
ParamName: String;
params: TArray<TRttiParameter>;
begin
Result := 'void';
ctx := TRttiContext.Create;
b := 0;
if( Assigned(GetClass(classname)) ) then
lType:=ctx.GetType(GetClass(classname));
try
if Assigned(lType) then
begin
lMethod:=lType.GetMethod(method);
if Assigned(lMethod) then
begin
if lMethod.IsStatic or lMethod.IsConstructor or lMethod.IsDestructor then
begin
Result := '!';
Exit;
end;
end
else
BEGIN
params := lMethod.GetParameters;
if not Assigned(params) then
Exit;
for x in params do
begin
if not Assigned(x) then Exit;
if (not x.Name.IsEmpty) then
begin
ParamName := '$';
if (b > 0) and (Length(params)>1) then Result := Result + ', ';
b := b + 1;
if pfConst in x.Flags then Result := Result + 'constant ';
if pfArray in x.Flags then Result := Result + 'array ';
if pfOut in x.Flags then Result := Result + '&';
if pfAddress in x.Flags then ParamName := '&$';
if not Assigned(x.ParamType) then Exit;
Result := Result + x.ParamType.ToString() + ' ' + ParamName + x.Name;
end;
end;
end;
end;
finally
ctx.Free();
end;
end;
{$IFDEF NEWRTTI}
function getProperty2(id: integer; prop: string): variant;
var
o: TObject;
inf: TRTTIType;
ctx: TRTTIContext;
p: TRttiProperty;
v: TValue;
begin
o := TObject(integer(id));
Result := Null;
if Assigned(o) then
begin
ctx := RTTI.TRttiContext.Create;
inf := ctx.GetType(o.ClassType);
if Assigned(inf) then
begin
p := Inf.GetProperty(prop);
if Assigned(p) then
begin
v := p.GetValue(o);
if v.Kind = tkEnumeration then
begin
Result := VariantFromValue(v);//GetDynArrayProp(o, prop);
end
else
begin
Result := VariantFromValue(v);
end;
p.Free;
inf.Free;
end;
end;
ctx.Free;
end;
end;
function setProperty2(o: TObject; prop: string; value: Variant): boolean;
var
inf: TRTTIType;
ctx: TRTTIContext;
p: TRttiProperty;
begin
Result := False;
if Assigned(o) then
begin
try
ctx := RTTI.TRttiContext.Create;
if not Assigned(GetClass(o.ClassName)) then begin
ctx.Free;
Exit;
end;
inf := ctx.GetType(o.ClassType);
if Assigned(inf) then
begin
p := Inf.GetProperty(prop);
if Assigned(p) then begin
{if prop = 'HintColor' then
ShowMessage( inttostr( integer( p.PropertyType.TypeKind ) ) );
}if p.IsWritable then
if p.PropertyType.TypeKind in [ tkInteger, tkInt64 , tkWChar
,tkChar, tkFloat, tkString, {tkClass, tkPointer,} tkUString, tkAnsiString,
tkWString {, tkVariant}] then
p.SetValue(o, ValueFromVariant(value, p.PropertyType.TypeKind))
else if p.PropertyType.TypeKind in [ tkClass, tkClassRef ] then
if VarType(value) = varNull then
p.SetValue(o, TValue.From<TObject>(nil))
else
p.SetValue(o, TValue.From<TObject>(TObject(integer(value))));
Result := True;
p.Free;
end;
inf.Free;
end;
except
on E:exception do
begin
ctx.Free;
Exit;
end;
end;
end;
end;
{$ENDIF}
function setProperty(id: integer; prop: string; Value: variant): boolean;
var