@live-codes/pascal-wasm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +501 -0
- package/README.md +278 -0
- package/THIRD-PARTY-NOTICES.md +48 -0
- package/assets/pas2js.wasm +0 -0
- package/assets/rtl/Rtl.BrowserLoadHelper.pas +179 -0
- package/assets/rtl/browserconsole.pas +190 -0
- package/assets/rtl/classes.pas +11371 -0
- package/assets/rtl/js.pas +2211 -0
- package/assets/rtl/manifest.json +19 -0
- package/assets/rtl/math.pas +903 -0
- package/assets/rtl/p2jsres.pp +334 -0
- package/assets/rtl/rtl.js +1563 -0
- package/assets/rtl/rtlconsts.pas +97 -0
- package/assets/rtl/simplelinkedlist.pas +152 -0
- package/assets/rtl/system.pas +1166 -0
- package/assets/rtl/sysutils.pas +8959 -0
- package/assets/rtl/types.pas +2296 -0
- package/assets/rtl/typinfo.pas +1680 -0
- package/assets/rtl/web.pas +3586 -0
- package/assets/rtl/weborworker.pas +2101 -0
- package/dist/pascal-wasm.iife.min.js +6 -0
- package/dist/pascal-wasm.iife.min.js.map +7 -0
- package/package.json +54 -0
- package/src/assets.js +119 -0
- package/src/compiler.js +142 -0
- package/src/config.js +24 -0
- package/src/iife.js +27 -0
- package/src/index.js +130 -0
- package/src/vendor/browser_wasi_shim/debug.js +1 -0
- package/src/vendor/browser_wasi_shim/fd.js +1 -0
- package/src/vendor/browser_wasi_shim/fs_mem.js +1 -0
- package/src/vendor/browser_wasi_shim/fs_opfs.js +1 -0
- package/src/vendor/browser_wasi_shim/index.js +1 -0
- package/src/vendor/browser_wasi_shim/strace.js +1 -0
- package/src/vendor/browser_wasi_shim/wasi.js +1 -0
- package/src/vendor/browser_wasi_shim/wasi_defs.js +1 -0
- package/types/index.d.ts +89 -0
|
@@ -0,0 +1,1680 @@
|
|
|
1
|
+
{
|
|
2
|
+
This file is part of the Pas2JS run time library.
|
|
3
|
+
Copyright (c) 2018 by Mattias Gaertner
|
|
4
|
+
|
|
5
|
+
See the file COPYING.FPC, included in this distribution,
|
|
6
|
+
for details about the copyright.
|
|
7
|
+
|
|
8
|
+
This program is distributed in the hope that it will be useful,
|
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
11
|
+
|
|
12
|
+
**********************************************************************}
|
|
13
|
+
{$IFNDEF FPC_DOTTEDUNITS}
|
|
14
|
+
unit TypInfo;
|
|
15
|
+
{$ENDIF}
|
|
16
|
+
|
|
17
|
+
{$mode objfpc}
|
|
18
|
+
{$modeswitch externalclass}
|
|
19
|
+
|
|
20
|
+
interface
|
|
21
|
+
|
|
22
|
+
uses
|
|
23
|
+
{$IFDEF FPC_DOTTEDUNITS}
|
|
24
|
+
System.SysUtils, System.Types, System.RTLConsts, JSApi.JS;
|
|
25
|
+
{$ELSE}
|
|
26
|
+
SysUtils, Types, RTLConsts, JS;
|
|
27
|
+
{$ENDIF}
|
|
28
|
+
|
|
29
|
+
type
|
|
30
|
+
// TCallConv for compatibility with Delphi/FPC, ignored under pas2js
|
|
31
|
+
TCallConv = (ccReg, ccCdecl, ccPascal, ccStdCall, ccSafeCall, ccCppdecl,
|
|
32
|
+
ccFar16, ccOldFPCCall, ccInternProc, ccSysCall, ccSoftFloat, ccMWPascal);
|
|
33
|
+
|
|
34
|
+
TPas2JSRtlCallback = class external name 'Function' (TJSFunction)
|
|
35
|
+
scope: TJSObject;
|
|
36
|
+
fn : JSValue; // string or TJSFunction
|
|
37
|
+
end;
|
|
38
|
+
|
|
39
|
+
TTypeInfoModule = class;
|
|
40
|
+
|
|
41
|
+
{ TSectionRTTI }
|
|
42
|
+
|
|
43
|
+
TSectionRTTI = class external name 'rtl.tSectionRTTI' (TJSObject)
|
|
44
|
+
Module: TTypeInfoModule external name '$module';
|
|
45
|
+
end;
|
|
46
|
+
|
|
47
|
+
{ TTypeInfoModule }
|
|
48
|
+
|
|
49
|
+
TTypeInfoModule = class external name 'Object'
|
|
50
|
+
public
|
|
51
|
+
Name: String external name '$name';
|
|
52
|
+
RTTI: TSectionRTTI external name '$rtti';
|
|
53
|
+
end;
|
|
54
|
+
|
|
55
|
+
TTypeInfoAttributes = type TJSValueDynArray;
|
|
56
|
+
|
|
57
|
+
{ TTypeInfo }
|
|
58
|
+
|
|
59
|
+
TTypeInfo = class external name 'rtl.tTypeInfo'
|
|
60
|
+
public
|
|
61
|
+
Name: String external name 'name';
|
|
62
|
+
Kind: TTypeKind external name 'kind';
|
|
63
|
+
Attributes: TTypeInfoAttributes external name 'attr'; // can be nil
|
|
64
|
+
Module: TTypeInfoModule external name '$module'; // can be nil
|
|
65
|
+
end;
|
|
66
|
+
TTypeInfoClassOf = class of TTypeInfo;
|
|
67
|
+
|
|
68
|
+
PTypeInfo = Pointer; // for compatibility with Delphi/FPC, under pas2js it is a TTypeInfo
|
|
69
|
+
|
|
70
|
+
TOrdType = (
|
|
71
|
+
otSByte, // 0
|
|
72
|
+
otUByte, // 1
|
|
73
|
+
otSWord, // 2
|
|
74
|
+
otUWord, // 3
|
|
75
|
+
otSLong, // 4
|
|
76
|
+
otULong, // 5
|
|
77
|
+
otSIntDouble, // 6 NativeInt
|
|
78
|
+
otUIntDouble // 7 NativeUInt
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
{ TTypeInfoInteger - Kind = tkInteger }
|
|
82
|
+
|
|
83
|
+
TTypeInfoInteger = class external name 'rtl.tTypeInfoInteger'(TTypeInfo)
|
|
84
|
+
public
|
|
85
|
+
MinValue: NativeInt external name 'minvalue';
|
|
86
|
+
MaxValue: NativeInt external name 'maxvalue';
|
|
87
|
+
OrdType : TOrdType external name 'ordtype';
|
|
88
|
+
end;
|
|
89
|
+
|
|
90
|
+
{ TEnumType }
|
|
91
|
+
|
|
92
|
+
TEnumType = class external name 'anonymous'
|
|
93
|
+
private
|
|
94
|
+
function GetIntToName(Index: NativeInt): String; external name '[]';
|
|
95
|
+
function GetNameToInt(Name: String): NativeInt; external name '[]';
|
|
96
|
+
public
|
|
97
|
+
property IntToName[Index: NativeInt]: String read GetIntToName;
|
|
98
|
+
property NameToInt[Name: String]: NativeInt read GetNameToInt;
|
|
99
|
+
end;
|
|
100
|
+
|
|
101
|
+
{ TTypeInfoEnum - Kind = tkEnumeration }
|
|
102
|
+
|
|
103
|
+
TTypeInfoEnum = class external name 'rtl.tTypeInfoEnum'(TTypeInfoInteger)
|
|
104
|
+
public
|
|
105
|
+
// not supported: BaseType: TTypeInfo
|
|
106
|
+
EnumType: TEnumType external name 'enumtype';
|
|
107
|
+
end;
|
|
108
|
+
|
|
109
|
+
{ TTypeInfoSet - Kind = tkSet }
|
|
110
|
+
|
|
111
|
+
TTypeInfoSet = class external name 'rtl.tTypeInfoSet'(TTypeInfo)
|
|
112
|
+
public
|
|
113
|
+
// not supported: BaseType: TTypeInfo
|
|
114
|
+
CompType: TTypeInfo external name 'comptype';
|
|
115
|
+
end;
|
|
116
|
+
|
|
117
|
+
{ TTypeInfoStaticArray - Kind = tkArray }
|
|
118
|
+
|
|
119
|
+
TTypeInfoStaticArray = class external name 'rtl.tTypeInfoStaticArray'(TTypeInfo)
|
|
120
|
+
public
|
|
121
|
+
Dims: TIntegerDynArray external name 'dims';
|
|
122
|
+
ElType: TTypeInfo external name 'eltype';
|
|
123
|
+
end;
|
|
124
|
+
|
|
125
|
+
{ TTypeInfoDynArray - Kind = tkDynArray }
|
|
126
|
+
|
|
127
|
+
TTypeInfoDynArray = class external name 'rtl.tTypeInfoDynArray'(TTypeInfo)
|
|
128
|
+
public
|
|
129
|
+
ElType: TTypeInfo external name 'eltype';
|
|
130
|
+
end;
|
|
131
|
+
|
|
132
|
+
TParamFlag = (
|
|
133
|
+
pfVar, // 2^0 = 1
|
|
134
|
+
pfConst, // 2^1 = 2
|
|
135
|
+
pfOut, // 2^2 = 4
|
|
136
|
+
pfArray, // 2^3 = 8
|
|
137
|
+
pfAddress, // 2^4 = 16
|
|
138
|
+
pfReference // 2^5 = 32
|
|
139
|
+
);
|
|
140
|
+
TParamFlags = set of TParamFlag;
|
|
141
|
+
|
|
142
|
+
{ TProcedureParam }
|
|
143
|
+
|
|
144
|
+
TProcedureParam = class external name 'anonymous'
|
|
145
|
+
public
|
|
146
|
+
Name: String external name 'name';
|
|
147
|
+
TypeInfo: TTypeInfo external name 'typeinfo';
|
|
148
|
+
Flags: NativeInt external name 'flags'; // TParamFlags as bit vector
|
|
149
|
+
end;
|
|
150
|
+
|
|
151
|
+
TProcedureParams = array of TProcedureParam;
|
|
152
|
+
|
|
153
|
+
TProcedureFlag = (
|
|
154
|
+
pfStatic, // 2^0 = 1
|
|
155
|
+
pfVarargs, // 2^1 = 2
|
|
156
|
+
pfExternal, // 2^2 = 4 name may be an expression
|
|
157
|
+
pfSafeCall, // 2^3 = 8
|
|
158
|
+
pfAsync // 2^4 = 16
|
|
159
|
+
);
|
|
160
|
+
TProcedureFlags = set of TProcedureFlag;
|
|
161
|
+
|
|
162
|
+
{ TProcedureSignature }
|
|
163
|
+
|
|
164
|
+
TProcedureSignature = class external name 'anonymous'
|
|
165
|
+
public
|
|
166
|
+
Params: TProcedureParams external name 'params'; // can be nil
|
|
167
|
+
ResultType: TTypeInfo external name 'resulttype'; // can be nil
|
|
168
|
+
Flags: NativeInt external name 'flags'; // TProcedureFlags as bit vector
|
|
169
|
+
end;
|
|
170
|
+
|
|
171
|
+
{ TTypeInfoProcVar - Kind = tkProcVar }
|
|
172
|
+
|
|
173
|
+
TTypeInfoProcVar = class external name 'rtl.tTypeInfoProcVar'(TTypeInfo)
|
|
174
|
+
public
|
|
175
|
+
ProcSig: TProcedureSignature external name 'procsig';
|
|
176
|
+
end;
|
|
177
|
+
|
|
178
|
+
{ TTypeInfoRefToProcVar - Kind = tkRefToProcVar }
|
|
179
|
+
|
|
180
|
+
TTypeInfoRefToProcVar = class external name 'rtl.tTypeInfoRefToProcVar'(TTypeInfoProcVar)
|
|
181
|
+
end;
|
|
182
|
+
|
|
183
|
+
TMethodKind = (
|
|
184
|
+
mkProcedure, // 0 default
|
|
185
|
+
mkFunction, // 1
|
|
186
|
+
mkConstructor, // 2
|
|
187
|
+
mkDestructor, // 3
|
|
188
|
+
mkClassProcedure,// 4
|
|
189
|
+
mkClassFunction // 5
|
|
190
|
+
//mkClassConstructor,mkClassDestructor,mkOperatorOverload
|
|
191
|
+
);
|
|
192
|
+
TMethodKinds = set of TMethodKind;
|
|
193
|
+
|
|
194
|
+
{ TTypeInfoMethodVar - Kind = tkMethod }
|
|
195
|
+
|
|
196
|
+
TTypeInfoMethodVar = class external name 'rtl.tTypeInfoMethodVar'(TTypeInfoProcVar)
|
|
197
|
+
public
|
|
198
|
+
MethodKind: TMethodKind external name 'methodkind';
|
|
199
|
+
end;
|
|
200
|
+
|
|
201
|
+
TTypeMemberKind = (
|
|
202
|
+
tmkUnknown, // 0
|
|
203
|
+
tmkField, // 1
|
|
204
|
+
tmkMethod, // 2
|
|
205
|
+
tmkProperty // 3
|
|
206
|
+
);
|
|
207
|
+
TTypeMemberKinds = set of TTypeMemberKind;
|
|
208
|
+
|
|
209
|
+
TTypeMemberVisibility = (
|
|
210
|
+
tmvPrivate, // 0
|
|
211
|
+
tmvProtected, // 1
|
|
212
|
+
tmvPublic, // 2
|
|
213
|
+
tmvPublished, // 3
|
|
214
|
+
tmvPublishedPublic,// 4, public for extended RTTI, published for basic RTTI, vcPublished was missing in the RTTI directive
|
|
215
|
+
tmvStrictPrivate, // 5
|
|
216
|
+
tmvStrictProtected // 6
|
|
217
|
+
);
|
|
218
|
+
TTypeMemberVisibilities = set of TTypeMemberVisibility;
|
|
219
|
+
|
|
220
|
+
{ TTypeMember }
|
|
221
|
+
|
|
222
|
+
TTypeMember = class external name 'rtl.tTypeMember'
|
|
223
|
+
public
|
|
224
|
+
Name: String external name 'name';
|
|
225
|
+
Kind: TTypeMemberKind external name 'kind';
|
|
226
|
+
Attributes: TTypeInfoAttributes external name 'attr'; // can be nil
|
|
227
|
+
Visibility: TTypeMemberVisibility external name 'visibility';
|
|
228
|
+
end;
|
|
229
|
+
TTypeMemberDynArray = array of TTypeMember;
|
|
230
|
+
|
|
231
|
+
{ TTypeMemberField - Kind = tmkField }
|
|
232
|
+
|
|
233
|
+
TTypeMemberField = class external name 'rtl.tTypeMemberField'(TTypeMember)
|
|
234
|
+
public
|
|
235
|
+
TypeInfo: TTypeInfo external name 'typeinfo';
|
|
236
|
+
end;
|
|
237
|
+
|
|
238
|
+
{ TTypeMemberMethod - Kind = tmkMethod }
|
|
239
|
+
|
|
240
|
+
TTypeMemberMethod = class external name 'rtl.tTypeMemberMethod'(TTypeMember)
|
|
241
|
+
public
|
|
242
|
+
MethodKind: TMethodKind external name 'methodkind';
|
|
243
|
+
ProcSig: TProcedureSignature external name 'procsig';
|
|
244
|
+
end;
|
|
245
|
+
TTypeMemberMethodDynArray = array of TTypeMemberMethod;
|
|
246
|
+
|
|
247
|
+
const
|
|
248
|
+
pfGetFunction = 1; // getter is a function
|
|
249
|
+
pfSetProcedure = 2; // setter is a procedure
|
|
250
|
+
// stored is a 2-bit vector:
|
|
251
|
+
pfStoredFalse = 4; // stored false, never
|
|
252
|
+
pfStoredField = 8; // stored field, field name is in Stored
|
|
253
|
+
pfStoredFunction = 12; // stored function, function name is in Stored
|
|
254
|
+
pfHasIndex = 16; { if getter is function, append Index as last param
|
|
255
|
+
if setter is function, append Index as second last param }
|
|
256
|
+
pfClassProperty = 32;
|
|
257
|
+
type
|
|
258
|
+
{ TTypeMemberProperty - Kind = tmkProperty }
|
|
259
|
+
|
|
260
|
+
TTypeMemberProperty = class external name 'rtl.tTypeMemberProperty'(TTypeMember)
|
|
261
|
+
public
|
|
262
|
+
TypeInfo: TTypeInfo external name 'typeinfo';
|
|
263
|
+
Flags: NativeInt external name 'flags'; // bit vector, see pf constants above
|
|
264
|
+
Params: TProcedureParams external name 'params'; // can be nil
|
|
265
|
+
Index: JSValue external name 'index'; // can be undefined
|
|
266
|
+
Getter: String external name 'getter'; // name of field or function
|
|
267
|
+
Setter: String external name 'setter'; // name of field or function
|
|
268
|
+
Stored: String external name 'stored'; // name of field or function, can be undefined
|
|
269
|
+
Default: JSValue external name 'Default'; // can be undefined
|
|
270
|
+
end;
|
|
271
|
+
TTypeMemberPropertyDynArray = array of TTypeMemberProperty;
|
|
272
|
+
|
|
273
|
+
{ TTypeMembers }
|
|
274
|
+
|
|
275
|
+
TTypeMembers = class external name 'rtl.tTypeMembers'
|
|
276
|
+
private
|
|
277
|
+
function GetItems(Name: String): TTypeMember; external name '[]';
|
|
278
|
+
procedure SetItems(Name: String; const AValue: TTypeMember); external name '[]';
|
|
279
|
+
public
|
|
280
|
+
property Members[Name: String]: TTypeMember read GetItems write SetItems; default;
|
|
281
|
+
end;
|
|
282
|
+
|
|
283
|
+
{ TTypeInfoStruct }
|
|
284
|
+
|
|
285
|
+
TTypeInfoStruct = class external name 'rtl.tTypeInfoStruct'(TTypeInfo)
|
|
286
|
+
private
|
|
287
|
+
FFieldCount: NativeInt external name 'fields.length';
|
|
288
|
+
FMethodCount: NativeInt external name 'methods.length';
|
|
289
|
+
FPropCount: NativeInt external name 'properties.length';
|
|
290
|
+
public
|
|
291
|
+
Members: TTypeMembers external name 'members';
|
|
292
|
+
Names: TStringDynArray external name 'names'; // all member names with TTypeInfo
|
|
293
|
+
Fields: TStringDynArray external name 'fields';
|
|
294
|
+
Methods: TStringDynArray external name 'methods';
|
|
295
|
+
Properties: TStringDynArray external name 'properties';
|
|
296
|
+
property FieldCount: NativeInt read FFieldCount;
|
|
297
|
+
function GetField(Index: NativeInt): TTypeMemberField; external name 'getField';
|
|
298
|
+
function AddField(aName: String; aType: TTypeInfo; Options: TJSObject = nil
|
|
299
|
+
): TTypeMemberField; external name 'addField';
|
|
300
|
+
property MethodCount: NativeInt read FMethodCount;
|
|
301
|
+
function GetMethod(Index: NativeInt): TTypeMemberMethod; external name 'getMethod';
|
|
302
|
+
function AddMethod(aName: String; MethodKind: TMethodKind = mkProcedure;
|
|
303
|
+
Params: TJSArray = nil; ResultType: TTypeInfo = nil;
|
|
304
|
+
Options: TJSObject = nil): TTypeMemberMethod; external name 'addMethod';
|
|
305
|
+
property PropCount: NativeInt read FPropCount;
|
|
306
|
+
function GetProp(Index: NativeInt): TTypeMemberProperty; external name 'getProperty';
|
|
307
|
+
function AddProperty(aName: String; Flags: NativeInt; ResultType: TTypeInfo;
|
|
308
|
+
Getter, Setter: String; Options: TJSObject = nil): TTypeMemberProperty; external name 'addProperty';
|
|
309
|
+
end;
|
|
310
|
+
|
|
311
|
+
{ TTypeInfoRecord - Kind = tkRecord }
|
|
312
|
+
|
|
313
|
+
TRecordInfo = class external name 'Object'(TJSObject)
|
|
314
|
+
public
|
|
315
|
+
function Assign(Source: JSValue): JSValue; reintroduce; external name '$assign';
|
|
316
|
+
function Clone(Source: JSValue): JSValue; external name '$clone';
|
|
317
|
+
function Equals(Source: JSValue): Boolean; external name '$eq';
|
|
318
|
+
function New: JSValue; reintroduce; external name '$new';
|
|
319
|
+
end;
|
|
320
|
+
|
|
321
|
+
TTypeInfoRecord = class external name 'rtl.tTypeInfoRecord'(TTypeInfoStruct)
|
|
322
|
+
public
|
|
323
|
+
RecordInfo: TRecordInfo external name '$record'; // only records rtti members, else jsundefined
|
|
324
|
+
end;
|
|
325
|
+
|
|
326
|
+
{ TTypeInfoClass - Kind = tkClass }
|
|
327
|
+
|
|
328
|
+
TTypeInfoClass = class external name 'rtl.tTypeInfoClass'(TTypeInfoStruct)
|
|
329
|
+
public
|
|
330
|
+
Ancestor: TTypeInfoClass external name 'ancestor';
|
|
331
|
+
ClassType: TClass external name 'class';
|
|
332
|
+
end;
|
|
333
|
+
|
|
334
|
+
{ TTypeInfoExtClass - Kind = tkExtClass }
|
|
335
|
+
|
|
336
|
+
TTypeInfoExtClass = class external name 'rtl.tTypeInfoExtClass'(TTypeInfo)
|
|
337
|
+
public
|
|
338
|
+
Ancestor: TTypeInfoExtClass external name 'ancestor';
|
|
339
|
+
JSClassName: String external name 'jsclass';
|
|
340
|
+
end;
|
|
341
|
+
|
|
342
|
+
{ TTypeInfoClassRef - class-of, Kind = tkClassRef }
|
|
343
|
+
|
|
344
|
+
TTypeInfoClassRef = class external name 'rtl.tTypeInfoClassRef'(TTypeInfo)
|
|
345
|
+
public
|
|
346
|
+
InstanceType: TTypeInfo external name 'instancetype';
|
|
347
|
+
end;
|
|
348
|
+
|
|
349
|
+
{ TTypeInfoPointer - Kind = tkPointer }
|
|
350
|
+
|
|
351
|
+
TTypeInfoPointer = class external name 'rtl.tTypeInfoPointer'(TTypeInfo)
|
|
352
|
+
public
|
|
353
|
+
RefType: TTypeInfo external name 'reftype'; // can be null
|
|
354
|
+
end;
|
|
355
|
+
|
|
356
|
+
TInterfaceInfo = class external name 'Object'(TJSObject)
|
|
357
|
+
FullName: String external name '$FullName';
|
|
358
|
+
GUID: String external name '$guid';
|
|
359
|
+
GUIDR: String external name '$guidr';
|
|
360
|
+
Kind: String external name '$kind';
|
|
361
|
+
Module: TTypeInfoModule external name '$module'; // can be nil
|
|
362
|
+
Name: String external name '$name';
|
|
363
|
+
Names: TStringArray external name '$names';
|
|
364
|
+
RTTI: TSectionRTTI external name '$rtti';
|
|
365
|
+
end;
|
|
366
|
+
|
|
367
|
+
{ TTypeInfoInterface - Kind = tkInterface }
|
|
368
|
+
|
|
369
|
+
TTypeInfoInterface = class external name 'rtl.tTypeInfoInterface'(TTypeInfoStruct)
|
|
370
|
+
public
|
|
371
|
+
InterfaceInfo: TInterfaceInfo external name 'interface';
|
|
372
|
+
Ancestor: TTypeInfoInterface external name 'ancestor';
|
|
373
|
+
end;
|
|
374
|
+
|
|
375
|
+
{ TTypeInfoHelper - Kind = tkHelper }
|
|
376
|
+
|
|
377
|
+
TTypeInfoHelper = class external name 'rtl.tTypeInfoHelper'(TTypeInfoStruct)
|
|
378
|
+
public
|
|
379
|
+
HelperType: TJSObject external name 'helper';
|
|
380
|
+
Ancestor: TTypeInfoHelper external name 'ancestor';
|
|
381
|
+
HelperFor: TTypeInfo external name 'helperfor';
|
|
382
|
+
end;
|
|
383
|
+
|
|
384
|
+
TReferenceVariable = class external name 'Object'
|
|
385
|
+
public
|
|
386
|
+
function get: JSValue;
|
|
387
|
+
procedure &set(const value: JSValue);
|
|
388
|
+
end;
|
|
389
|
+
|
|
390
|
+
EPropertyError = class(Exception);
|
|
391
|
+
|
|
392
|
+
function GetTypeName(TypeInfo: TTypeInfo): string;
|
|
393
|
+
|
|
394
|
+
function GetClassMembers(aTIStruct: TTypeInfoStruct): TTypeMemberDynArray;
|
|
395
|
+
function GetClassMember(aTIStruct: TTypeInfoStruct; const aName: String): TTypeMember;
|
|
396
|
+
function GetInstanceMethod(Instance: TObject; const aName: String): Pointer;
|
|
397
|
+
function GetClassMethods(aTIStruct: TTypeInfoStruct): TTypeMemberMethodDynArray;
|
|
398
|
+
function CreateMethod(Instance: TObject; FuncName: String): Pointer; external name 'rtl.createCallback';
|
|
399
|
+
|
|
400
|
+
function GetInterfaceMembers(aTIInterface: TTypeInfoInterface): TTypeMemberDynArray;
|
|
401
|
+
function GetInterfaceMember(aTIInterface: TTypeInfoInterface; const aName: String): TTypeMember;
|
|
402
|
+
function GetInterfaceMethods(aTIInterface: TTypeInfoInterface): TTypeMemberMethodDynArray;
|
|
403
|
+
|
|
404
|
+
function GetRTTIAttributes(const Attributes: TTypeInfoAttributes): TCustomAttributeArray;
|
|
405
|
+
|
|
406
|
+
function GetPropInfos(aTIStruct: TTypeInfoStruct): TTypeMemberPropertyDynArray;
|
|
407
|
+
function GetPropList(aTIStruct: TTypeInfoStruct; TypeKinds: TTypeKinds; Sorted: boolean = true): TTypeMemberPropertyDynArray;
|
|
408
|
+
function GetPropList(aTIStruct: TTypeInfoStruct): TTypeMemberPropertyDynArray;
|
|
409
|
+
function GetPropList(AClass: TClass): TTypeMemberPropertyDynArray;
|
|
410
|
+
function GetPropList(Instance: TObject): TTypeMemberPropertyDynArray;
|
|
411
|
+
|
|
412
|
+
function GetPropInfo(TI: TTypeInfoStruct; const PropName: String): TTypeMemberProperty;
|
|
413
|
+
function GetPropInfo(TI: TTypeInfoStruct; const PropName: String; const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
414
|
+
function GetPropInfo(Instance: TObject; const PropName: String): TTypeMemberProperty;
|
|
415
|
+
function GetPropInfo(Instance: TObject; const PropName: String; const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
416
|
+
function GetPropInfo(aClass: TClass; const PropName: String): TTypeMemberProperty;
|
|
417
|
+
function GetPropInfo(aClass: TClass; const PropName: String; const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
418
|
+
|
|
419
|
+
function FindPropInfo(Instance: TObject; const PropName: String): TTypeMemberProperty;
|
|
420
|
+
function FindPropInfo(Instance: TObject; const PropName: String; const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
421
|
+
function FindPropInfo(aClass: TClass; const PropName: String): TTypeMemberProperty;
|
|
422
|
+
function FindPropInfo(aClass: TClass; const PropName: String; const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
423
|
+
|
|
424
|
+
// Property information routines.
|
|
425
|
+
Function IsStoredProp(Instance: TObject; const PropInfo: TTypeMemberProperty): Boolean;
|
|
426
|
+
Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
|
|
427
|
+
function IsPublishedProp(Instance: TObject; const PropName: String): Boolean;
|
|
428
|
+
function IsPublishedProp(aClass: TClass; const PropName: String): Boolean;
|
|
429
|
+
function PropType(Instance: TObject; const PropName: string): TTypeKind;
|
|
430
|
+
function PropType(aClass: TClass; const PropName: string): TTypeKind;
|
|
431
|
+
function PropIsType(Instance: TObject; const PropName: string; const TypeKind: TTypeKind): Boolean;
|
|
432
|
+
function PropIsType(aClass: TClass; const PropName: string; const TypeKind: TTypeKind): Boolean;
|
|
433
|
+
|
|
434
|
+
function GetJSValueProp(Instance: TJSObject; TI: TTypeInfoStruct; const PropName: String): JSValue;
|
|
435
|
+
function GetJSValueProp(Instance: TJSObject; const PropInfo: TTypeMemberProperty): JSValue;
|
|
436
|
+
function GetJSValueProp(Instance: TObject; const PropName: String): JSValue;
|
|
437
|
+
function GetJSValueProp(Instance: TObject; const PropInfo: TTypeMemberProperty): JSValue;
|
|
438
|
+
procedure SetJSValueProp(Instance: TJSObject; TI: TTypeInfoStruct; const PropName: String; Value: JSValue);
|
|
439
|
+
procedure SetJSValueProp(Instance: TJSObject; const PropInfo: TTypeMemberProperty; Value: JSValue);
|
|
440
|
+
procedure SetJSValueProp(Instance: TObject; const PropName: String; Value: JSValue);
|
|
441
|
+
procedure SetJSValueProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: JSValue);
|
|
442
|
+
|
|
443
|
+
function GetNativeIntProp(Instance: TObject; const PropName: String): NativeInt;
|
|
444
|
+
function GetNativeIntProp(Instance: TObject; const PropInfo: TTypeMemberProperty): NativeInt;
|
|
445
|
+
procedure SetNativeIntProp(Instance: TObject; const PropName: String; Value: NativeInt);
|
|
446
|
+
procedure SetNativeIntProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: NativeInt);
|
|
447
|
+
|
|
448
|
+
function GetOrdProp(Instance: TObject; const PropName: String): longint;
|
|
449
|
+
function GetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty): longint;
|
|
450
|
+
procedure SetOrdProp(Instance: TObject; const PropName: String; Value: longint);
|
|
451
|
+
procedure SetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: longint);
|
|
452
|
+
|
|
453
|
+
function GetEnumProp(Instance: TObject; const PropName: String): String;
|
|
454
|
+
function GetEnumProp(Instance: TObject; const PropInfo: TTypeMemberProperty): String;
|
|
455
|
+
procedure SetEnumProp(Instance: TObject; const PropName: String; const Value: String);
|
|
456
|
+
procedure SetEnumProp(Instance: TObject; const PropInfo: TTypeMemberProperty; const Value: String);
|
|
457
|
+
// Auxiliary routines, which may be useful
|
|
458
|
+
function GetEnumName(TypeInfo: TTypeInfo; Value: Integer): String;
|
|
459
|
+
function GetEnumValue(TypeInfo: TTypeInfo; const Name: string): Longint;
|
|
460
|
+
function GetEnumNameCount(TypeInfo: TTypeInfo): Longint;
|
|
461
|
+
|
|
462
|
+
function GetSetProp(Instance: TObject; const PropName: String): String; overload;
|
|
463
|
+
function GetSetProp(Instance: TObject; const PropInfo: TTypeMemberProperty): String; overload;
|
|
464
|
+
function GetSetPropArray(Instance: TObject; const PropName: String): TIntegerDynArray; overload;
|
|
465
|
+
function GetSetPropArray(Instance: TObject; const PropInfo: TTypeMemberProperty): TIntegerDynArray; overload;
|
|
466
|
+
procedure SetSetPropArray(Instance: TObject; const PropName: String; const Arr: TIntegerDynArray); overload;
|
|
467
|
+
procedure SetSetPropArray(Instance: TObject; const PropInfo: TTypeMemberProperty; const Arr: TIntegerDynArray); overload;
|
|
468
|
+
|
|
469
|
+
function GetBoolProp(Instance: TObject; const PropName: String): boolean;
|
|
470
|
+
function GetBoolProp(Instance: TObject; const PropInfo: TTypeMemberProperty): boolean;
|
|
471
|
+
procedure SetBoolProp(Instance: TObject; const PropName: String; Value: boolean);
|
|
472
|
+
procedure SetBoolProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: boolean);
|
|
473
|
+
|
|
474
|
+
function GetStrProp(Instance: TObject; const PropName: String): String;
|
|
475
|
+
function GetStrProp(Instance: TObject; const PropInfo: TTypeMemberProperty): String;
|
|
476
|
+
procedure SetStrProp(Instance: TObject; const PropName: String; Value: String);
|
|
477
|
+
procedure SetStrProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: String);
|
|
478
|
+
|
|
479
|
+
function GetStringProp(Instance: TObject; const PropName: String): String; deprecated; // use GetStrProp
|
|
480
|
+
function GetStringProp(Instance: TObject; const PropInfo: TTypeMemberProperty): String; deprecated; // use GetStrProp
|
|
481
|
+
procedure SetStringProp(Instance: TObject; const PropName: String; Value: String); deprecated; // use GetStrProp
|
|
482
|
+
procedure SetStringProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: String); deprecated; // use GetStrProp
|
|
483
|
+
|
|
484
|
+
function GetFloatProp(Instance: TObject; const PropName: string): Double;
|
|
485
|
+
function GetFloatProp(Instance: TObject; PropInfo : TTypeMemberProperty) : Double;
|
|
486
|
+
procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Double);
|
|
487
|
+
procedure SetFloatProp(Instance: TObject; PropInfo : TTypeMemberProperty; Value : Double);
|
|
488
|
+
|
|
489
|
+
function GetObjectProp(Instance: TObject; const PropName: String): TObject;
|
|
490
|
+
function GetObjectProp(Instance: TObject; const PropName: String; MinClass: TClass): TObject;
|
|
491
|
+
function GetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty): TObject;
|
|
492
|
+
function GetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty; MinClass: TClass): TObject;
|
|
493
|
+
procedure SetObjectProp(Instance: TObject; const PropName: String; Value: TObject) ;
|
|
494
|
+
procedure SetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: TObject);
|
|
495
|
+
|
|
496
|
+
function GetMethodProp(Instance: TObject; PropInfo: TTypeMemberProperty): TMethod;
|
|
497
|
+
function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
|
|
498
|
+
procedure SetMethodProp(Instance: TObject; PropInfo: TTypeMemberProperty; const Value : TMethod);
|
|
499
|
+
procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
|
|
500
|
+
|
|
501
|
+
function GetInterfaceProp(Instance: TObject; const PropName: string): IInterface;
|
|
502
|
+
function GetInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty): IInterface;
|
|
503
|
+
procedure SetInterfaceProp(Instance: TObject; const PropName: string; const Value: IInterface);
|
|
504
|
+
procedure SetInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty; const Value: IInterface);
|
|
505
|
+
|
|
506
|
+
function GetRawInterfaceProp(Instance: TObject; const PropName: string): Pointer;
|
|
507
|
+
function GetRawInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty): Pointer;
|
|
508
|
+
procedure SetRawInterfaceProp(Instance: TObject; const PropName: string; const Value: Pointer);
|
|
509
|
+
procedure SetRawInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty; const Value: Pointer);
|
|
510
|
+
|
|
511
|
+
function SetToString(TypeInfo: TTypeInfo; Value: JSValue; Brackets: Boolean) : String;
|
|
512
|
+
function SetToString(PropInfo: TTypeMemberProperty; Value: JSValue; Brackets: Boolean) : String;
|
|
513
|
+
function SetToString(PropInfo: TTypeMemberProperty; Value: JSValue) : String;
|
|
514
|
+
|
|
515
|
+
implementation
|
|
516
|
+
|
|
517
|
+
function GetTypeName(TypeInfo: TTypeInfo): string;
|
|
518
|
+
begin
|
|
519
|
+
Result := TypeInfo.Name;
|
|
520
|
+
end;
|
|
521
|
+
|
|
522
|
+
function GetClassMembers(aTIStruct: TTypeInfoStruct): TTypeMemberDynArray;
|
|
523
|
+
var
|
|
524
|
+
C: TTypeInfoStruct;
|
|
525
|
+
i: Integer;
|
|
526
|
+
PropName: String;
|
|
527
|
+
Names: TJSObject;
|
|
528
|
+
begin
|
|
529
|
+
Result:=nil;
|
|
530
|
+
Names:=TJSObject.new;
|
|
531
|
+
C:=aTIStruct;
|
|
532
|
+
while C<>nil do
|
|
533
|
+
begin
|
|
534
|
+
for i:=0 to length(C.Names)-1 do
|
|
535
|
+
begin
|
|
536
|
+
PropName:=C.Names[i];
|
|
537
|
+
if Names.hasOwnProperty(PropName) then continue;
|
|
538
|
+
TJSArray(Result).push(C.Members[PropName]);
|
|
539
|
+
Names[PropName]:=true;
|
|
540
|
+
end;
|
|
541
|
+
if not (C is TTypeInfoClass) then break;
|
|
542
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
543
|
+
end;
|
|
544
|
+
end;
|
|
545
|
+
|
|
546
|
+
function GetClassMember(aTIStruct: TTypeInfoStruct; const aName: String): TTypeMember;
|
|
547
|
+
var
|
|
548
|
+
C: TTypeInfoStruct;
|
|
549
|
+
i: Integer;
|
|
550
|
+
begin
|
|
551
|
+
// quick search: case sensitive
|
|
552
|
+
C:=aTIStruct;
|
|
553
|
+
while C<>nil do
|
|
554
|
+
begin
|
|
555
|
+
if TJSObject(C.Members).hasOwnProperty(aName) then
|
|
556
|
+
exit(C.Members[aName]);
|
|
557
|
+
if not (C is TTypeInfoClass) then break;
|
|
558
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
559
|
+
end;
|
|
560
|
+
// slow search: case insensitive
|
|
561
|
+
C:=aTIStruct;
|
|
562
|
+
while C<>nil do
|
|
563
|
+
begin
|
|
564
|
+
for i:=0 to length(C.Names)-1 do
|
|
565
|
+
if CompareText(C.Names[i],aName)=0 then
|
|
566
|
+
exit(C.Members[C.Names[i]]);
|
|
567
|
+
if not (C is TTypeInfoClass) then break;
|
|
568
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
569
|
+
end;
|
|
570
|
+
Result:=nil;
|
|
571
|
+
end;
|
|
572
|
+
|
|
573
|
+
function GetInstanceMethod(Instance: TObject; const aName: String): Pointer;
|
|
574
|
+
var
|
|
575
|
+
TI: TTypeMember;
|
|
576
|
+
begin
|
|
577
|
+
if Instance=nil then exit(nil);
|
|
578
|
+
TI:=GetClassMember(TypeInfo(Instance),aName);
|
|
579
|
+
if not (TI is TTypeMemberMethod) then exit(nil);
|
|
580
|
+
Result:=CreateMethod(Instance,TI.Name); // Note: use TI.Name for the correct case!
|
|
581
|
+
end;
|
|
582
|
+
|
|
583
|
+
function GetClassMethods(aTIStruct: TTypeInfoStruct): TTypeMemberMethodDynArray;
|
|
584
|
+
var
|
|
585
|
+
C: TTypeInfoStruct;
|
|
586
|
+
i, Cnt, j: Integer;
|
|
587
|
+
begin
|
|
588
|
+
Cnt:=0;
|
|
589
|
+
C:=aTIStruct;
|
|
590
|
+
while C<>nil do
|
|
591
|
+
begin
|
|
592
|
+
inc(Cnt,C.MethodCount);
|
|
593
|
+
if not (C is TTypeInfoClass) then break;
|
|
594
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
595
|
+
end;
|
|
596
|
+
SetLength(Result,Cnt);
|
|
597
|
+
C:=aTIStruct;
|
|
598
|
+
i:=0;
|
|
599
|
+
while C<>nil do
|
|
600
|
+
begin
|
|
601
|
+
for j:=0 to C.MethodCount-1 do
|
|
602
|
+
begin
|
|
603
|
+
Result[i]:=TTypeMemberMethod(C.Members[C.Methods[j]]);
|
|
604
|
+
inc(i);
|
|
605
|
+
end;
|
|
606
|
+
if not (C is TTypeInfoClass) then break;
|
|
607
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
608
|
+
end;
|
|
609
|
+
end;
|
|
610
|
+
|
|
611
|
+
function GetInterfaceMembers(aTIInterface: TTypeInfoInterface
|
|
612
|
+
): TTypeMemberDynArray;
|
|
613
|
+
var
|
|
614
|
+
Intf: TTypeInfoInterface;
|
|
615
|
+
i, Cnt, j: Integer;
|
|
616
|
+
begin
|
|
617
|
+
Cnt:=0;
|
|
618
|
+
Intf:=aTIInterface;
|
|
619
|
+
while Intf<>nil do
|
|
620
|
+
begin
|
|
621
|
+
inc(Cnt,length(Intf.Names));
|
|
622
|
+
Intf:=Intf.Ancestor;
|
|
623
|
+
end;
|
|
624
|
+
SetLength(Result,Cnt);
|
|
625
|
+
Intf:=aTIInterface;
|
|
626
|
+
i:=0;
|
|
627
|
+
while Intf<>nil do
|
|
628
|
+
begin
|
|
629
|
+
for j:=0 to length(Intf.Names)-1 do
|
|
630
|
+
begin
|
|
631
|
+
Result[i]:=Intf.Members[Intf.Names[j]];
|
|
632
|
+
inc(i);
|
|
633
|
+
end;
|
|
634
|
+
Intf:=Intf.Ancestor;
|
|
635
|
+
end;
|
|
636
|
+
end;
|
|
637
|
+
|
|
638
|
+
function GetInterfaceMember(aTIInterface: TTypeInfoInterface;
|
|
639
|
+
const aName: String): TTypeMember;
|
|
640
|
+
var
|
|
641
|
+
Intf: TTypeInfoInterface;
|
|
642
|
+
i: Integer;
|
|
643
|
+
begin
|
|
644
|
+
// quick search: case sensitive
|
|
645
|
+
Intf:=aTIInterface;
|
|
646
|
+
while Intf<>nil do
|
|
647
|
+
begin
|
|
648
|
+
if TJSObject(Intf.Members).hasOwnProperty(aName) then
|
|
649
|
+
exit(Intf.Members[aName]);
|
|
650
|
+
Intf:=Intf.Ancestor;
|
|
651
|
+
end;
|
|
652
|
+
// slow search: case insensitive
|
|
653
|
+
Intf:=aTIInterface;
|
|
654
|
+
while Intf<>nil do
|
|
655
|
+
begin
|
|
656
|
+
for i:=0 to length(Intf.Names)-1 do
|
|
657
|
+
if CompareText(Intf.Names[i],aName)=0 then
|
|
658
|
+
exit(Intf.Members[Intf.Names[i]]);
|
|
659
|
+
Intf:=Intf.Ancestor;
|
|
660
|
+
end;
|
|
661
|
+
Result:=nil;
|
|
662
|
+
end;
|
|
663
|
+
|
|
664
|
+
function GetInterfaceMethods(aTIInterface: TTypeInfoInterface
|
|
665
|
+
): TTypeMemberMethodDynArray;
|
|
666
|
+
var
|
|
667
|
+
Intf: TTypeInfoInterface;
|
|
668
|
+
i, Cnt, j: Integer;
|
|
669
|
+
begin
|
|
670
|
+
Cnt:=0;
|
|
671
|
+
Intf:=aTIInterface;
|
|
672
|
+
while Intf<>nil do
|
|
673
|
+
begin
|
|
674
|
+
inc(Cnt,Intf.MethodCount);
|
|
675
|
+
Intf:=Intf.Ancestor;
|
|
676
|
+
end;
|
|
677
|
+
SetLength(Result,Cnt);
|
|
678
|
+
Intf:=aTIInterface;
|
|
679
|
+
i:=0;
|
|
680
|
+
while Intf<>nil do
|
|
681
|
+
begin
|
|
682
|
+
for j:=0 to Intf.MethodCount-1 do
|
|
683
|
+
begin
|
|
684
|
+
Result[i]:=TTypeMemberMethod(Intf.Members[Intf.Methods[j]]);
|
|
685
|
+
inc(i);
|
|
686
|
+
end;
|
|
687
|
+
Intf:=Intf.Ancestor;
|
|
688
|
+
end;
|
|
689
|
+
end;
|
|
690
|
+
|
|
691
|
+
type
|
|
692
|
+
TCreatorAttribute = class external name 'attr'
|
|
693
|
+
class function Create(const ProcName: string): TCustomAttribute; overload; external name '$create';
|
|
694
|
+
class function Create(const ProcName: string; Params: jsvalue): TCustomAttribute; overload; external name '$create';
|
|
695
|
+
end;
|
|
696
|
+
TCreatorAttributeClass = class of TCreatorAttribute;
|
|
697
|
+
|
|
698
|
+
function GetRTTIAttributes(const Attributes: TTypeInfoAttributes
|
|
699
|
+
): TCustomAttributeArray;
|
|
700
|
+
var
|
|
701
|
+
i, len: Integer;
|
|
702
|
+
AttrClass: TCreatorAttributeClass;
|
|
703
|
+
ProcName: String;
|
|
704
|
+
Attr: TCustomAttribute;
|
|
705
|
+
begin
|
|
706
|
+
Result:=nil;
|
|
707
|
+
if Attributes=Undefined then exit;
|
|
708
|
+
i:=0;
|
|
709
|
+
len:=length(Attributes);
|
|
710
|
+
while i<len do
|
|
711
|
+
begin
|
|
712
|
+
AttrClass:=TCreatorAttributeClass(Attributes[i]);
|
|
713
|
+
inc(i);
|
|
714
|
+
ProcName:=String(Attributes[i]);
|
|
715
|
+
inc(i);
|
|
716
|
+
if (i<len) and isArray(Attributes[i]) then
|
|
717
|
+
begin
|
|
718
|
+
Attr:=AttrClass.Create(ProcName,Attributes[i]);
|
|
719
|
+
inc(i);
|
|
720
|
+
end
|
|
721
|
+
else
|
|
722
|
+
Attr:=AttrClass.Create(ProcName);
|
|
723
|
+
Insert(Attr,Result,length(Result));
|
|
724
|
+
end;
|
|
725
|
+
end;
|
|
726
|
+
|
|
727
|
+
function GetPropInfos(aTIStruct: TTypeInfoStruct): TTypeMemberPropertyDynArray;
|
|
728
|
+
var
|
|
729
|
+
C: TTypeInfoStruct;
|
|
730
|
+
i: Integer;
|
|
731
|
+
Names: TJSObject;
|
|
732
|
+
PropName: String;
|
|
733
|
+
Prop: TTypeMemberProperty;
|
|
734
|
+
begin
|
|
735
|
+
Result:=nil;
|
|
736
|
+
C:=aTIStruct;
|
|
737
|
+
Names:=TJSObject.new;
|
|
738
|
+
while C<>nil do
|
|
739
|
+
begin
|
|
740
|
+
for i:=0 to C.PropCount-1 do
|
|
741
|
+
begin
|
|
742
|
+
PropName:=C.Properties[i];
|
|
743
|
+
if Names.hasOwnProperty(PropName) then continue;
|
|
744
|
+
Prop:=TTypeMemberProperty(C.Members[PropName]);
|
|
745
|
+
if Prop.Visibility<tmvPublished then continue;
|
|
746
|
+
TJSArray(Result).push(Prop);
|
|
747
|
+
Names[PropName]:=true;
|
|
748
|
+
end;
|
|
749
|
+
if not (C is TTypeInfoClass) then
|
|
750
|
+
break;
|
|
751
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
752
|
+
end;
|
|
753
|
+
end;
|
|
754
|
+
|
|
755
|
+
function GetPropList(aTIStruct: TTypeInfoStruct; TypeKinds: TTypeKinds;
|
|
756
|
+
Sorted: boolean): TTypeMemberPropertyDynArray;
|
|
757
|
+
|
|
758
|
+
function NameSort(a,b: JSValue): NativeInt;
|
|
759
|
+
begin
|
|
760
|
+
if TTypeMemberProperty(a).Name<TTypeMemberProperty(b).Name then
|
|
761
|
+
Result:=-1
|
|
762
|
+
else if TTypeMemberProperty(a).Name>TTypeMemberProperty(b).Name then
|
|
763
|
+
Result:=1
|
|
764
|
+
else
|
|
765
|
+
Result:=0;
|
|
766
|
+
end;
|
|
767
|
+
|
|
768
|
+
var
|
|
769
|
+
C: TTypeInfoStruct;
|
|
770
|
+
i: Integer;
|
|
771
|
+
Names: TJSObject;
|
|
772
|
+
PropName: String;
|
|
773
|
+
Prop: TTypeMemberProperty;
|
|
774
|
+
begin
|
|
775
|
+
Result:=nil;
|
|
776
|
+
C:=aTIStruct;
|
|
777
|
+
Names:=TJSObject.new;
|
|
778
|
+
while C<>nil do
|
|
779
|
+
begin
|
|
780
|
+
for i:=0 to C.PropCount-1 do
|
|
781
|
+
begin
|
|
782
|
+
PropName:=C.Properties[i];
|
|
783
|
+
if Names.hasOwnProperty(PropName) then continue;
|
|
784
|
+
Prop:=TTypeMemberProperty(C.Members[PropName]);
|
|
785
|
+
if not (Prop.TypeInfo.Kind in TypeKinds) then continue;
|
|
786
|
+
if Prop.Visibility<tmvPublished then continue;
|
|
787
|
+
TJSArray(Result).push(Prop);
|
|
788
|
+
Names[PropName]:=true;
|
|
789
|
+
end;
|
|
790
|
+
if not (C is TTypeInfoClass) then
|
|
791
|
+
break;
|
|
792
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
793
|
+
end;
|
|
794
|
+
if Sorted then
|
|
795
|
+
TJSArray(Result).sort(@NameSort);
|
|
796
|
+
end;
|
|
797
|
+
|
|
798
|
+
function GetPropList(aTIStruct: TTypeInfoStruct): TTypeMemberPropertyDynArray;
|
|
799
|
+
begin
|
|
800
|
+
Result:=GetPropInfos(aTIStruct);
|
|
801
|
+
end;
|
|
802
|
+
|
|
803
|
+
function GetPropList(AClass: TClass): TTypeMemberPropertyDynArray;
|
|
804
|
+
begin
|
|
805
|
+
Result:=GetPropInfos(TypeInfo(AClass));
|
|
806
|
+
end;
|
|
807
|
+
|
|
808
|
+
function GetPropList(Instance: TObject): TTypeMemberPropertyDynArray;
|
|
809
|
+
begin
|
|
810
|
+
Result:=GetPropList(Instance.ClassType);
|
|
811
|
+
end;
|
|
812
|
+
|
|
813
|
+
function GetPropInfo(TI: TTypeInfoStruct; const PropName: String
|
|
814
|
+
): TTypeMemberProperty;
|
|
815
|
+
var
|
|
816
|
+
m: TTypeMember;
|
|
817
|
+
i: Integer;
|
|
818
|
+
C: TTypeInfoStruct;
|
|
819
|
+
Prop: TTypeMemberProperty;
|
|
820
|
+
begin
|
|
821
|
+
// quick search case sensitive
|
|
822
|
+
C:=TI;
|
|
823
|
+
while C<>nil do
|
|
824
|
+
begin
|
|
825
|
+
m:=C.Members[PropName];
|
|
826
|
+
if m is TTypeMemberProperty then
|
|
827
|
+
begin
|
|
828
|
+
Prop:=TTypeMemberProperty(m);
|
|
829
|
+
if Prop.Visibility>=tmvPublished then
|
|
830
|
+
exit(Prop);
|
|
831
|
+
end;
|
|
832
|
+
if not (C is TTypeInfoClass) then
|
|
833
|
+
break;
|
|
834
|
+
C:=TTypeInfoClass(C).Ancestor;
|
|
835
|
+
end;
|
|
836
|
+
|
|
837
|
+
// slow search case insensitive
|
|
838
|
+
Result:=nil;
|
|
839
|
+
repeat
|
|
840
|
+
for i:=0 to TI.PropCount-1 do
|
|
841
|
+
if CompareText(PropName,TI.Properties[i])=0 then
|
|
842
|
+
begin
|
|
843
|
+
m:=TI.Members[TI.Properties[i]];
|
|
844
|
+
if m is TTypeMemberProperty then
|
|
845
|
+
begin
|
|
846
|
+
Prop:=TTypeMemberProperty(m);
|
|
847
|
+
if Prop.Visibility>=tmvPublished then
|
|
848
|
+
exit(Prop);
|
|
849
|
+
end;
|
|
850
|
+
end;
|
|
851
|
+
if not (TI is TTypeInfoClass) then
|
|
852
|
+
break;
|
|
853
|
+
TI:=TTypeInfoClass(TI).Ancestor;
|
|
854
|
+
until TI=nil;
|
|
855
|
+
end;
|
|
856
|
+
|
|
857
|
+
function GetPropInfo(TI: TTypeInfoStruct; const PropName: String;
|
|
858
|
+
const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
859
|
+
begin
|
|
860
|
+
Result:=GetPropInfo(TI,PropName);
|
|
861
|
+
if (Kinds<>[]) and (Result<>nil) and not (Result.TypeInfo.Kind in Kinds) then
|
|
862
|
+
Result:=nil;
|
|
863
|
+
end;
|
|
864
|
+
|
|
865
|
+
function GetPropInfo(Instance: TObject; const PropName: String
|
|
866
|
+
): TTypeMemberProperty;
|
|
867
|
+
begin
|
|
868
|
+
Result:=GetPropInfo(TypeInfo(Instance),PropName,[]);
|
|
869
|
+
end;
|
|
870
|
+
|
|
871
|
+
function GetPropInfo(Instance: TObject; const PropName: String;
|
|
872
|
+
const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
873
|
+
begin
|
|
874
|
+
Result:=GetPropInfo(TypeInfo(Instance),PropName,Kinds);
|
|
875
|
+
end;
|
|
876
|
+
|
|
877
|
+
function GetPropInfo(aClass: TClass; const PropName: String
|
|
878
|
+
): TTypeMemberProperty;
|
|
879
|
+
begin
|
|
880
|
+
Result:=GetPropInfo(TypeInfo(AClass),PropName,[]);
|
|
881
|
+
end;
|
|
882
|
+
|
|
883
|
+
function GetPropInfo(aClass: TClass; const PropName: String;
|
|
884
|
+
const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
885
|
+
begin
|
|
886
|
+
Result:=GetPropInfo(TypeInfo(AClass),PropName,Kinds);
|
|
887
|
+
end;
|
|
888
|
+
|
|
889
|
+
function FindPropInfo(Instance: TObject; const PropName: String
|
|
890
|
+
): TTypeMemberProperty;
|
|
891
|
+
begin
|
|
892
|
+
Result:=GetPropInfo(TypeInfo(Instance), PropName);
|
|
893
|
+
if Result=nil then
|
|
894
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
895
|
+
end;
|
|
896
|
+
|
|
897
|
+
function FindPropInfo(Instance: TObject; const PropName: String;
|
|
898
|
+
const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
899
|
+
begin
|
|
900
|
+
Result:=GetPropInfo(TypeInfo(Instance), PropName, Kinds);
|
|
901
|
+
if Result=nil then
|
|
902
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
903
|
+
end;
|
|
904
|
+
|
|
905
|
+
function FindPropInfo(aClass: TClass; const PropName: String
|
|
906
|
+
): TTypeMemberProperty;
|
|
907
|
+
begin
|
|
908
|
+
Result:=GetPropInfo(TypeInfo(aClass), PropName);
|
|
909
|
+
if Result=nil then
|
|
910
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
911
|
+
end;
|
|
912
|
+
|
|
913
|
+
function FindPropInfo(aClass: TClass; const PropName: String;
|
|
914
|
+
const Kinds: TTypeKinds): TTypeMemberProperty;
|
|
915
|
+
begin
|
|
916
|
+
Result:=GetPropInfo(TypeInfo(aClass), PropName, Kinds);
|
|
917
|
+
if Result=nil then
|
|
918
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
919
|
+
end;
|
|
920
|
+
|
|
921
|
+
function IsStoredProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
922
|
+
): Boolean;
|
|
923
|
+
type
|
|
924
|
+
TIsStored = function: Boolean of object;
|
|
925
|
+
begin
|
|
926
|
+
case PropInfo.Flags and 12 of
|
|
927
|
+
0: Result:=true;
|
|
928
|
+
4: Result:=false;
|
|
929
|
+
8: Result:=Boolean(TJSObject(Instance)[PropInfo.Stored]);
|
|
930
|
+
else Result:=TIsStored(TJSObject(Instance)[PropInfo.Stored])();
|
|
931
|
+
end;
|
|
932
|
+
end;
|
|
933
|
+
|
|
934
|
+
function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
|
|
935
|
+
begin
|
|
936
|
+
Result:=IsStoredProp(Instance,FindPropInfo(Instance,PropName));
|
|
937
|
+
end;
|
|
938
|
+
|
|
939
|
+
function IsPublishedProp(Instance: TObject; const PropName: String): Boolean;
|
|
940
|
+
begin
|
|
941
|
+
Result:=GetPropInfo(Instance,PropName)<>nil;
|
|
942
|
+
end;
|
|
943
|
+
|
|
944
|
+
function IsPublishedProp(aClass: TClass; const PropName: String): Boolean;
|
|
945
|
+
begin
|
|
946
|
+
Result:=GetPropInfo(aClass,PropName)<>nil;
|
|
947
|
+
end;
|
|
948
|
+
|
|
949
|
+
function PropType(Instance: TObject; const PropName: string): TTypeKind;
|
|
950
|
+
begin
|
|
951
|
+
Result:=FindPropInfo(Instance,PropName).TypeInfo.Kind;
|
|
952
|
+
end;
|
|
953
|
+
|
|
954
|
+
function PropType(aClass: TClass; const PropName: string): TTypeKind;
|
|
955
|
+
begin
|
|
956
|
+
Result:=FindPropInfo(aClass,PropName).TypeInfo.Kind;
|
|
957
|
+
end;
|
|
958
|
+
|
|
959
|
+
function PropIsType(Instance: TObject; const PropName: string;
|
|
960
|
+
const TypeKind: TTypeKind): Boolean;
|
|
961
|
+
begin
|
|
962
|
+
Result:=PropType(Instance,PropName)=TypeKind;
|
|
963
|
+
end;
|
|
964
|
+
|
|
965
|
+
function PropIsType(aClass: TClass; const PropName: string;
|
|
966
|
+
const TypeKind: TTypeKind): Boolean;
|
|
967
|
+
begin
|
|
968
|
+
Result:=PropType(aClass,PropName)=TypeKind;
|
|
969
|
+
end;
|
|
970
|
+
|
|
971
|
+
type
|
|
972
|
+
TGetterKind = (
|
|
973
|
+
gkNone,
|
|
974
|
+
gkField,
|
|
975
|
+
gkFunction,
|
|
976
|
+
gkFunctionWithParams
|
|
977
|
+
);
|
|
978
|
+
|
|
979
|
+
function GetPropGetterKind(const PropInfo: TTypeMemberProperty): TGetterKind;
|
|
980
|
+
begin
|
|
981
|
+
if PropInfo.Getter='' then
|
|
982
|
+
Result:=gkNone
|
|
983
|
+
else if (pfGetFunction and PropInfo.Flags)>0 then
|
|
984
|
+
begin
|
|
985
|
+
if length(PropInfo.Params)>0 then
|
|
986
|
+
// array property
|
|
987
|
+
Result:=gkFunctionWithParams
|
|
988
|
+
else
|
|
989
|
+
Result:=gkFunction;
|
|
990
|
+
end
|
|
991
|
+
else
|
|
992
|
+
Result:=gkField;
|
|
993
|
+
end;
|
|
994
|
+
|
|
995
|
+
type
|
|
996
|
+
TSetterKind = (
|
|
997
|
+
skNone,
|
|
998
|
+
skField,
|
|
999
|
+
skProcedure,
|
|
1000
|
+
skProcedureWithParams
|
|
1001
|
+
);
|
|
1002
|
+
|
|
1003
|
+
function GetPropSetterKind(const PropInfo: TTypeMemberProperty): TSetterKind;
|
|
1004
|
+
begin
|
|
1005
|
+
if PropInfo.Setter='' then
|
|
1006
|
+
Result:=skNone
|
|
1007
|
+
else if (pfSetProcedure and PropInfo.Flags)>0 then
|
|
1008
|
+
begin
|
|
1009
|
+
if length(PropInfo.Params)>0 then
|
|
1010
|
+
// array property
|
|
1011
|
+
Result:=skProcedureWithParams
|
|
1012
|
+
else
|
|
1013
|
+
Result:=skProcedure;
|
|
1014
|
+
end
|
|
1015
|
+
else
|
|
1016
|
+
Result:=skField;
|
|
1017
|
+
end;
|
|
1018
|
+
|
|
1019
|
+
function GetJSValueProp(Instance: TJSObject; TI: TTypeInfoStruct;
|
|
1020
|
+
const PropName: String): JSValue;
|
|
1021
|
+
var
|
|
1022
|
+
PropInfo: TTypeMemberProperty;
|
|
1023
|
+
begin
|
|
1024
|
+
PropInfo:=GetPropInfo(TI,PropName);
|
|
1025
|
+
if PropInfo=nil then
|
|
1026
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
1027
|
+
Result:=GetJSValueProp(Instance,PropInfo);
|
|
1028
|
+
end;
|
|
1029
|
+
|
|
1030
|
+
function GetJSValueProp(Instance: TJSObject;
|
|
1031
|
+
const PropInfo: TTypeMemberProperty): JSValue;
|
|
1032
|
+
type
|
|
1033
|
+
TGetter = function: JSValue of object;
|
|
1034
|
+
TGetterWithIndex = function(Index: JSValue): JSValue of object;
|
|
1035
|
+
var
|
|
1036
|
+
gk: TGetterKind;
|
|
1037
|
+
begin
|
|
1038
|
+
gk:=GetPropGetterKind(PropInfo);
|
|
1039
|
+
case gk of
|
|
1040
|
+
gkNone:
|
|
1041
|
+
raise EPropertyError.CreateFmt(SCantReadPropertyS, [PropInfo.Name]);
|
|
1042
|
+
gkField:
|
|
1043
|
+
Result:=Instance[PropInfo.Getter];
|
|
1044
|
+
gkFunction:
|
|
1045
|
+
if (pfHasIndex and PropInfo.Flags)>0 then
|
|
1046
|
+
Result:=TGetterWithIndex(Instance[PropInfo.Getter])(PropInfo.Index)
|
|
1047
|
+
else
|
|
1048
|
+
Result:=TGetter(Instance[PropInfo.Getter])();
|
|
1049
|
+
gkFunctionWithParams:
|
|
1050
|
+
raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
|
|
1051
|
+
end;
|
|
1052
|
+
end;
|
|
1053
|
+
|
|
1054
|
+
function GetJSValueProp(Instance: TObject; const PropName: String): JSValue;
|
|
1055
|
+
begin
|
|
1056
|
+
Result:=GetJSValueProp(Instance,FindPropInfo(Instance,PropName));
|
|
1057
|
+
end;
|
|
1058
|
+
|
|
1059
|
+
function GetJSValueProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1060
|
+
): JSValue;
|
|
1061
|
+
begin
|
|
1062
|
+
Result:=GetJSValueProp(TJSObject(Instance),PropInfo);
|
|
1063
|
+
end;
|
|
1064
|
+
|
|
1065
|
+
procedure SetJSValueProp(Instance: TJSObject; TI: TTypeInfoStruct;
|
|
1066
|
+
const PropName: String; Value: JSValue);
|
|
1067
|
+
var
|
|
1068
|
+
PropInfo: TTypeMemberProperty;
|
|
1069
|
+
begin
|
|
1070
|
+
PropInfo:=GetPropInfo(TI,PropName);
|
|
1071
|
+
if PropInfo=nil then
|
|
1072
|
+
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
|
|
1073
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1074
|
+
end;
|
|
1075
|
+
|
|
1076
|
+
Function TransFormRawValue(aValue : JSValue; const PropInfo :TTypeInfo) : JSValue;
|
|
1077
|
+
|
|
1078
|
+
begin
|
|
1079
|
+
if isNumber(aValue) and (PropInfo=System.TypeInfo(Currency)) then
|
|
1080
|
+
Result:=Double(aValue)*10000
|
|
1081
|
+
else
|
|
1082
|
+
Result:=aValue;
|
|
1083
|
+
end;
|
|
1084
|
+
|
|
1085
|
+
procedure SetJSValueProp(Instance: TJSObject;
|
|
1086
|
+
const PropInfo: TTypeMemberProperty; Value: JSValue);
|
|
1087
|
+
type
|
|
1088
|
+
TSetter = procedure(Value: JSValue) of object;
|
|
1089
|
+
TSetterWithIndex = procedure(Index, Value: JSValue) of object;
|
|
1090
|
+
var
|
|
1091
|
+
sk: TSetterKind;
|
|
1092
|
+
lValue : JSValue;
|
|
1093
|
+
begin
|
|
1094
|
+
lValue:=TransFormRawValue(Value,PropInfo.TypeInfo);
|
|
1095
|
+
sk:=GetPropSetterKind(PropInfo);
|
|
1096
|
+
case sk of
|
|
1097
|
+
skNone:
|
|
1098
|
+
raise EPropertyError.CreateFmt(SCantWritePropertyS, [PropInfo.Name]);
|
|
1099
|
+
skField:
|
|
1100
|
+
Instance[PropInfo.Setter]:=lValue;
|
|
1101
|
+
skProcedure:
|
|
1102
|
+
if (pfHasIndex and PropInfo.Flags)>0 then
|
|
1103
|
+
TSetterWithIndex(Instance[PropInfo.Setter])(PropInfo.Index,lValue)
|
|
1104
|
+
else
|
|
1105
|
+
TSetter(Instance[PropInfo.Setter])(lValue);
|
|
1106
|
+
skProcedureWithParams:
|
|
1107
|
+
raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
|
|
1108
|
+
end;
|
|
1109
|
+
end;
|
|
1110
|
+
|
|
1111
|
+
procedure SetJSValueProp(Instance: TObject; const PropName: String;
|
|
1112
|
+
Value: JSValue);
|
|
1113
|
+
begin
|
|
1114
|
+
SetJSValueProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1115
|
+
end;
|
|
1116
|
+
|
|
1117
|
+
procedure SetJSValueProp(Instance: TObject;
|
|
1118
|
+
const PropInfo: TTypeMemberProperty; Value: JSValue);
|
|
1119
|
+
begin
|
|
1120
|
+
SetJSValueProp(TJSObject(Instance),PropInfo,Value);
|
|
1121
|
+
end;
|
|
1122
|
+
|
|
1123
|
+
function GetNativeIntProp(Instance: TObject; const PropName: String): NativeInt;
|
|
1124
|
+
begin
|
|
1125
|
+
Result:=GetNativeIntProp(Instance,FindPropInfo(Instance,PropName));
|
|
1126
|
+
end;
|
|
1127
|
+
|
|
1128
|
+
function GetNativeIntProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1129
|
+
): NativeInt;
|
|
1130
|
+
begin
|
|
1131
|
+
Result:=NativeInt(GetJSValueProp(Instance,PropInfo));
|
|
1132
|
+
end;
|
|
1133
|
+
|
|
1134
|
+
procedure SetNativeIntProp(Instance: TObject; const PropName: String;
|
|
1135
|
+
Value: NativeInt);
|
|
1136
|
+
begin
|
|
1137
|
+
SetJSValueProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1138
|
+
end;
|
|
1139
|
+
|
|
1140
|
+
procedure SetNativeIntProp(Instance: TObject;
|
|
1141
|
+
const PropInfo: TTypeMemberProperty; Value: NativeInt);
|
|
1142
|
+
begin
|
|
1143
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1144
|
+
end;
|
|
1145
|
+
|
|
1146
|
+
function GetOrdProp(Instance: TObject; const PropName: String): longint;
|
|
1147
|
+
begin
|
|
1148
|
+
Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
|
|
1149
|
+
end;
|
|
1150
|
+
|
|
1151
|
+
function GetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1152
|
+
): longint;
|
|
1153
|
+
var
|
|
1154
|
+
o: TJSObject;
|
|
1155
|
+
Key: String;
|
|
1156
|
+
n: NativeInt;
|
|
1157
|
+
v : JSValue;
|
|
1158
|
+
vs : TJSString absolute key;
|
|
1159
|
+
|
|
1160
|
+
begin
|
|
1161
|
+
if PropInfo.TypeInfo.Kind=tkSet then
|
|
1162
|
+
begin
|
|
1163
|
+
// a set is a JS object, with the following property: o[ElementDecimal]=true
|
|
1164
|
+
o:=TJSObject(GetJSValueProp(Instance,PropInfo));
|
|
1165
|
+
Result:=0;
|
|
1166
|
+
for Key in o do
|
|
1167
|
+
begin
|
|
1168
|
+
n:=parseInt(Key,10);
|
|
1169
|
+
if n<32 then
|
|
1170
|
+
Result:=Result+(1 shl n);
|
|
1171
|
+
end;
|
|
1172
|
+
end else if PropInfo.TypeInfo.Kind=tkChar then
|
|
1173
|
+
begin
|
|
1174
|
+
v:=GetJSValueProp(Instance,PropInfo);
|
|
1175
|
+
if isNumber(v) then
|
|
1176
|
+
Result:=Longint(V)
|
|
1177
|
+
else
|
|
1178
|
+
begin
|
|
1179
|
+
Key:=String(v);
|
|
1180
|
+
If Key='' then
|
|
1181
|
+
Result:=0
|
|
1182
|
+
else
|
|
1183
|
+
Result:=vs.CharCodeAt(0);
|
|
1184
|
+
end
|
|
1185
|
+
end else
|
|
1186
|
+
Result:=longint(GetJSValueProp(Instance,PropInfo));
|
|
1187
|
+
end;
|
|
1188
|
+
|
|
1189
|
+
procedure SetOrdProp(Instance: TObject; const PropName: String; Value: longint);
|
|
1190
|
+
begin
|
|
1191
|
+
SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1192
|
+
end;
|
|
1193
|
+
|
|
1194
|
+
procedure SetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
|
1195
|
+
Value: longint);
|
|
1196
|
+
var
|
|
1197
|
+
o: TJSObject;
|
|
1198
|
+
i: Integer;
|
|
1199
|
+
begin
|
|
1200
|
+
if PropInfo.TypeInfo.Kind=tkSet then
|
|
1201
|
+
begin
|
|
1202
|
+
o:=TJSObject.new;
|
|
1203
|
+
for i:=0 to 31 do
|
|
1204
|
+
if (1 shl i) and Value>0 then
|
|
1205
|
+
o[str(i)]:=true;
|
|
1206
|
+
SetJSValueProp(Instance,PropInfo,o);
|
|
1207
|
+
end else if PropInfo.TypeInfo.Kind=tkChar then
|
|
1208
|
+
SetJSValueProp(Instance,PropInfo,TJSString.fromCharCode(Value))
|
|
1209
|
+
else
|
|
1210
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1211
|
+
end;
|
|
1212
|
+
|
|
1213
|
+
function GetEnumProp(Instance: TObject; const PropName: String): String;
|
|
1214
|
+
begin
|
|
1215
|
+
Result:=GetEnumProp(Instance,FindPropInfo(Instance,PropName));
|
|
1216
|
+
end;
|
|
1217
|
+
|
|
1218
|
+
function GetEnumProp(Instance: TObject; const PropInfo: TTypeMemberProperty): String;
|
|
1219
|
+
var
|
|
1220
|
+
n: NativeInt;
|
|
1221
|
+
TIEnum: TTypeInfoEnum;
|
|
1222
|
+
begin
|
|
1223
|
+
TIEnum:=PropInfo.TypeInfo as TTypeInfoEnum;
|
|
1224
|
+
n:=NativeInt(GetJSValueProp(Instance,PropInfo));
|
|
1225
|
+
if (n>=TIEnum.MinValue) and (n<=TIEnum.MaxValue) then
|
|
1226
|
+
Result:=TIEnum.EnumType.IntToName[n]
|
|
1227
|
+
else
|
|
1228
|
+
Result:=str(n);
|
|
1229
|
+
end;
|
|
1230
|
+
|
|
1231
|
+
procedure SetEnumProp(Instance: TObject; const PropName: String;
|
|
1232
|
+
const Value: String);
|
|
1233
|
+
begin
|
|
1234
|
+
SetEnumProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1235
|
+
end;
|
|
1236
|
+
|
|
1237
|
+
procedure SetEnumProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
|
1238
|
+
const Value: String);
|
|
1239
|
+
var
|
|
1240
|
+
TIEnum: TTypeInfoEnum;
|
|
1241
|
+
n: NativeInt;
|
|
1242
|
+
begin
|
|
1243
|
+
TIEnum:=PropInfo.TypeInfo as TTypeInfoEnum;
|
|
1244
|
+
n:=TIEnum.EnumType.NameToInt[Value];
|
|
1245
|
+
if not isUndefined(n) then
|
|
1246
|
+
SetJSValueProp(Instance,PropInfo,n);
|
|
1247
|
+
end;
|
|
1248
|
+
|
|
1249
|
+
function GetEnumName(TypeInfo: TTypeInfo; Value: Integer): String;
|
|
1250
|
+
var
|
|
1251
|
+
Info: TTypeInfoEnum absolute TypeInfo;
|
|
1252
|
+
|
|
1253
|
+
begin
|
|
1254
|
+
Result := Info.EnumType.IntToName[Value];
|
|
1255
|
+
end;
|
|
1256
|
+
|
|
1257
|
+
function GetEnumValue(TypeInfo: TTypeInfo; const Name: string): Longint;
|
|
1258
|
+
var
|
|
1259
|
+
Info: TTypeInfoEnum absolute TypeInfo;
|
|
1260
|
+
|
|
1261
|
+
begin
|
|
1262
|
+
Result := Info.EnumType.NameToInt[Name];
|
|
1263
|
+
end;
|
|
1264
|
+
|
|
1265
|
+
function GetEnumNameCount(TypeInfo: TTypeInfo): Longint;
|
|
1266
|
+
var
|
|
1267
|
+
Info: TTypeInfoEnum absolute TypeInfo;
|
|
1268
|
+
o: TJSObject;
|
|
1269
|
+
l, r: LongInt;
|
|
1270
|
+
begin
|
|
1271
|
+
o:=TJSObject(Info.EnumType);
|
|
1272
|
+
// as of pas2js 1.0 the RTTI does not contain a min/max value
|
|
1273
|
+
// -> use exponential search
|
|
1274
|
+
// ToDo: adapt this once enums with gaps are supported
|
|
1275
|
+
Result:=1;
|
|
1276
|
+
while o.hasOwnProperty(String(JSValue(Result))) do
|
|
1277
|
+
Result:=Result*2;
|
|
1278
|
+
l:=Result div 2;
|
|
1279
|
+
r:=Result;
|
|
1280
|
+
while l<=r do
|
|
1281
|
+
begin
|
|
1282
|
+
Result:=(l+r) div 2;
|
|
1283
|
+
if o.hasOwnProperty(String(JSValue(Result))) then
|
|
1284
|
+
l:=Result+1
|
|
1285
|
+
else
|
|
1286
|
+
r:=Result-1;
|
|
1287
|
+
end;
|
|
1288
|
+
if o.hasOwnProperty(String(JSValue(Result))) then
|
|
1289
|
+
inc(Result);
|
|
1290
|
+
end;
|
|
1291
|
+
|
|
1292
|
+
function GetSetProp(Instance: TObject; const PropName: String): String;
|
|
1293
|
+
begin
|
|
1294
|
+
Result:=GetSetProp(Instance,FindPropInfo(Instance,PropName));
|
|
1295
|
+
end;
|
|
1296
|
+
|
|
1297
|
+
function GetSetProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1298
|
+
): String;
|
|
1299
|
+
var
|
|
1300
|
+
o: TJSObject;
|
|
1301
|
+
begin
|
|
1302
|
+
o:=TJSObject(GetJSValueProp(Instance,PropInfo));
|
|
1303
|
+
Result:=SetToString(PropInfo,o,true);
|
|
1304
|
+
end;
|
|
1305
|
+
|
|
1306
|
+
function GetSetPropArray(Instance: TObject; const PropName: String
|
|
1307
|
+
): TIntegerDynArray;
|
|
1308
|
+
begin
|
|
1309
|
+
Result:=GetSetPropArray(Instance,FindPropInfo(Instance,PropName));
|
|
1310
|
+
end;
|
|
1311
|
+
|
|
1312
|
+
function GetSetPropArray(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1313
|
+
): TIntegerDynArray;
|
|
1314
|
+
var
|
|
1315
|
+
o: TJSObject;
|
|
1316
|
+
Key: string;
|
|
1317
|
+
begin
|
|
1318
|
+
Result:=[];
|
|
1319
|
+
// read value
|
|
1320
|
+
o:=TJSObject(GetJSValueProp(Instance,PropInfo));
|
|
1321
|
+
// a set is a JS object, where included element is stored as: o[ElementDecimal]=true
|
|
1322
|
+
for Key in o do
|
|
1323
|
+
TJSArray(Result).push(parseInt(Key,10));
|
|
1324
|
+
end;
|
|
1325
|
+
|
|
1326
|
+
procedure SetSetPropArray(Instance: TObject; const PropName: String;
|
|
1327
|
+
const Arr: TIntegerDynArray);
|
|
1328
|
+
begin
|
|
1329
|
+
SetSetPropArray(Instance,FindPropInfo(Instance,PropName),Arr);
|
|
1330
|
+
end;
|
|
1331
|
+
|
|
1332
|
+
procedure SetSetPropArray(Instance: TObject;
|
|
1333
|
+
const PropInfo: TTypeMemberProperty; const Arr: TIntegerDynArray);
|
|
1334
|
+
var
|
|
1335
|
+
o: TJSObject;
|
|
1336
|
+
i: integer;
|
|
1337
|
+
begin
|
|
1338
|
+
o:=TJSObject.new;
|
|
1339
|
+
for i in Arr do
|
|
1340
|
+
o[str(i)]:=true;
|
|
1341
|
+
SetJSValueProp(Instance,PropInfo,o);
|
|
1342
|
+
end;
|
|
1343
|
+
|
|
1344
|
+
function GetStrProp(Instance: TObject; const PropName: String): String;
|
|
1345
|
+
begin
|
|
1346
|
+
Result:=GetStrProp(Instance,FindPropInfo(Instance,PropName));
|
|
1347
|
+
end;
|
|
1348
|
+
|
|
1349
|
+
function GetStrProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1350
|
+
): String;
|
|
1351
|
+
begin
|
|
1352
|
+
Result:=String(GetJSValueProp(Instance,PropInfo));
|
|
1353
|
+
end;
|
|
1354
|
+
|
|
1355
|
+
procedure SetStrProp(Instance: TObject; const PropName: String; Value: String
|
|
1356
|
+
);
|
|
1357
|
+
begin
|
|
1358
|
+
SetStrProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1359
|
+
end;
|
|
1360
|
+
|
|
1361
|
+
procedure SetStrProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
|
1362
|
+
Value: String);
|
|
1363
|
+
begin
|
|
1364
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1365
|
+
end;
|
|
1366
|
+
|
|
1367
|
+
function GetStringProp(Instance: TObject; const PropName: String): String;
|
|
1368
|
+
begin
|
|
1369
|
+
Result:=GetStrProp(Instance,PropName);
|
|
1370
|
+
end;
|
|
1371
|
+
|
|
1372
|
+
function GetStringProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1373
|
+
): String;
|
|
1374
|
+
begin
|
|
1375
|
+
Result:=GetStrProp(Instance,PropInfo);
|
|
1376
|
+
end;
|
|
1377
|
+
|
|
1378
|
+
procedure SetStringProp(Instance: TObject; const PropName: String; Value: String
|
|
1379
|
+
);
|
|
1380
|
+
begin
|
|
1381
|
+
SetStrProp(Instance,PropName,Value);
|
|
1382
|
+
end;
|
|
1383
|
+
|
|
1384
|
+
procedure SetStringProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
|
1385
|
+
Value: String);
|
|
1386
|
+
begin
|
|
1387
|
+
SetStrProp(Instance,PropInfo,Value);
|
|
1388
|
+
end;
|
|
1389
|
+
|
|
1390
|
+
function GetBoolProp(Instance: TObject; const PropName: String): boolean;
|
|
1391
|
+
begin
|
|
1392
|
+
Result:=GetBoolProp(Instance,FindPropInfo(Instance,PropName));
|
|
1393
|
+
end;
|
|
1394
|
+
|
|
1395
|
+
function GetBoolProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
|
1396
|
+
): boolean;
|
|
1397
|
+
begin
|
|
1398
|
+
Result:=Boolean(GetJSValueProp(Instance,PropInfo));
|
|
1399
|
+
end;
|
|
1400
|
+
|
|
1401
|
+
procedure SetBoolProp(Instance: TObject; const PropName: String; Value: boolean
|
|
1402
|
+
);
|
|
1403
|
+
begin
|
|
1404
|
+
SetBoolProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1405
|
+
end;
|
|
1406
|
+
|
|
1407
|
+
procedure SetBoolProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
|
1408
|
+
Value: boolean);
|
|
1409
|
+
begin
|
|
1410
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1411
|
+
end;
|
|
1412
|
+
|
|
1413
|
+
function GetObjectProp(Instance: TObject; const PropName: String): TObject;
|
|
1414
|
+
begin
|
|
1415
|
+
Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName));
|
|
1416
|
+
end;
|
|
1417
|
+
|
|
1418
|
+
function GetObjectProp(Instance: TObject; const PropName: String; MinClass : TClass): TObject;
|
|
1419
|
+
begin
|
|
1420
|
+
Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName));
|
|
1421
|
+
if (MinClass<>Nil) and (Result<>Nil) Then
|
|
1422
|
+
if not Result.InheritsFrom(MinClass) then
|
|
1423
|
+
Result:=Nil;
|
|
1424
|
+
end;
|
|
1425
|
+
|
|
1426
|
+
function GetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty): TObject;
|
|
1427
|
+
|
|
1428
|
+
begin
|
|
1429
|
+
Result:=GetObjectProp(Instance,PropInfo,Nil);
|
|
1430
|
+
end;
|
|
1431
|
+
|
|
1432
|
+
function GetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty; MinClass : TClass): TObject;
|
|
1433
|
+
|
|
1434
|
+
Var
|
|
1435
|
+
O : TObject;
|
|
1436
|
+
|
|
1437
|
+
begin
|
|
1438
|
+
O:=TObject(GetJSValueProp(Instance,PropInfo));
|
|
1439
|
+
if (MinClass<>Nil) and not O.InheritsFrom(MinClass) then
|
|
1440
|
+
Result:=Nil
|
|
1441
|
+
else
|
|
1442
|
+
Result:=O;
|
|
1443
|
+
end;
|
|
1444
|
+
|
|
1445
|
+
procedure SetObjectProp(Instance: TObject; const PropName: String; Value: TObject) ;
|
|
1446
|
+
|
|
1447
|
+
begin
|
|
1448
|
+
SetObjectProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1449
|
+
end;
|
|
1450
|
+
|
|
1451
|
+
procedure SetObjectProp(Instance: TObject; const PropInfo: TTypeMemberProperty; Value: TObject);
|
|
1452
|
+
|
|
1453
|
+
begin
|
|
1454
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1455
|
+
end;
|
|
1456
|
+
|
|
1457
|
+
function GetMethodProp(Instance: TObject; PropInfo: TTypeMemberProperty
|
|
1458
|
+
): TMethod;
|
|
1459
|
+
var
|
|
1460
|
+
v, fn: JSValue;
|
|
1461
|
+
begin
|
|
1462
|
+
Result.Code:=nil;
|
|
1463
|
+
Result.Data:=nil;
|
|
1464
|
+
v:=GetJSValueProp(Instance,PropInfo);
|
|
1465
|
+
if not isFunction(v) then exit;
|
|
1466
|
+
Result.Data:=Pointer(TJSObject(v)['scope']);
|
|
1467
|
+
fn:=TJSObject(v)['fn'];
|
|
1468
|
+
if isString(fn) then
|
|
1469
|
+
begin
|
|
1470
|
+
if Result.Data<>nil then
|
|
1471
|
+
// named callback
|
|
1472
|
+
Result.Code:=CodePointer(TJSObject(Result.Data)[String(fn)])
|
|
1473
|
+
else
|
|
1474
|
+
// this is not an rtl callback, return the value
|
|
1475
|
+
Result.Code:=CodePointer(v);
|
|
1476
|
+
end
|
|
1477
|
+
else
|
|
1478
|
+
// anonymous callback
|
|
1479
|
+
Result.Code:=CodePointer(fn);
|
|
1480
|
+
end;
|
|
1481
|
+
|
|
1482
|
+
function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
|
|
1483
|
+
begin
|
|
1484
|
+
Result:=GetMethodProp(Instance,FindPropInfo(Instance,PropName));
|
|
1485
|
+
end;
|
|
1486
|
+
|
|
1487
|
+
function createCallbackPtr(scope: Pointer; fn: CodePointer): TJSFunction; external name 'rtl.createCallback';
|
|
1488
|
+
function createCallbackStr(scope: Pointer; fn: string): TJSFunction; external name 'rtl.createCallback';
|
|
1489
|
+
|
|
1490
|
+
procedure SetMethodProp(Instance: TObject; PropInfo: TTypeMemberProperty;
|
|
1491
|
+
const Value: TMethod);
|
|
1492
|
+
var
|
|
1493
|
+
cb: TJSFunction;
|
|
1494
|
+
Code: Pointer;
|
|
1495
|
+
begin
|
|
1496
|
+
// Note: Value.Data=nil is allowed and can be used by designer code
|
|
1497
|
+
Code:=Value.Code;
|
|
1498
|
+
if Code=nil then
|
|
1499
|
+
cb:=nil
|
|
1500
|
+
else if isFunction(Code) then
|
|
1501
|
+
begin
|
|
1502
|
+
if (TJSObject(Code)['scope']=Value.Data)
|
|
1503
|
+
and (isFunction(TJSObject(Code)['fn']) or isString(TJSObject(Code)['fn']))
|
|
1504
|
+
then
|
|
1505
|
+
begin
|
|
1506
|
+
// Value.Code is already the needed callback
|
|
1507
|
+
cb:=TJSFunction(Code);
|
|
1508
|
+
end
|
|
1509
|
+
else if isString(TJSObject(Code)['fn']) then
|
|
1510
|
+
// named callback, different scope
|
|
1511
|
+
cb:=createCallbackStr(Value.Data,string(TJSObject(Code)['fn']))
|
|
1512
|
+
else
|
|
1513
|
+
// normal function
|
|
1514
|
+
cb:=createCallbackPtr(Value.Data,Code);
|
|
1515
|
+
end
|
|
1516
|
+
else
|
|
1517
|
+
// not a valid value -> for compatibility set it anyway
|
|
1518
|
+
cb:=createCallbackPtr(Value.Data,Code);
|
|
1519
|
+
SetJSValueProp(Instance,PropInfo,cb);
|
|
1520
|
+
end;
|
|
1521
|
+
|
|
1522
|
+
procedure SetMethodProp(Instance: TObject; const PropName: string;
|
|
1523
|
+
const Value: TMethod);
|
|
1524
|
+
begin
|
|
1525
|
+
SetMethodProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1526
|
+
end;
|
|
1527
|
+
|
|
1528
|
+
function GetInterfaceProp(Instance: TObject; const PropName: string
|
|
1529
|
+
): IInterface;
|
|
1530
|
+
begin
|
|
1531
|
+
Result:=GetInterfaceProp(Instance,FindPropInfo(Instance,PropName));
|
|
1532
|
+
end;
|
|
1533
|
+
|
|
1534
|
+
function GetInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty
|
|
1535
|
+
): IInterface;
|
|
1536
|
+
type
|
|
1537
|
+
TGetter = function: IInterface of object;
|
|
1538
|
+
TGetterWithIndex = function(Index: JSValue): IInterface of object;
|
|
1539
|
+
var
|
|
1540
|
+
gk: TGetterKind;
|
|
1541
|
+
begin
|
|
1542
|
+
if Propinfo.TypeInfo.Kind<>tkInterface then
|
|
1543
|
+
raise Exception.Create('Cannot get RAW interface from IInterface interface');
|
|
1544
|
+
gk:=GetPropGetterKind(PropInfo);
|
|
1545
|
+
case gk of
|
|
1546
|
+
gkNone:
|
|
1547
|
+
raise EPropertyError.CreateFmt(SCantReadPropertyS, [PropInfo.Name]);
|
|
1548
|
+
gkField:
|
|
1549
|
+
Result:=IInterface(TJSObject(Instance)[PropInfo.Getter]);
|
|
1550
|
+
gkFunction:
|
|
1551
|
+
if (pfHasIndex and PropInfo.Flags)>0 then
|
|
1552
|
+
Result:=TGetterWithIndex(TJSObject(Instance)[PropInfo.Getter])(PropInfo.Index)
|
|
1553
|
+
else
|
|
1554
|
+
Result:=TGetter(TJSObject(Instance)[PropInfo.Getter])();
|
|
1555
|
+
gkFunctionWithParams:
|
|
1556
|
+
raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
|
|
1557
|
+
end;
|
|
1558
|
+
end;
|
|
1559
|
+
|
|
1560
|
+
procedure SetInterfaceProp(Instance: TObject; const PropName: string;
|
|
1561
|
+
const Value: IInterface);
|
|
1562
|
+
begin
|
|
1563
|
+
SetInterfaceProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1564
|
+
end;
|
|
1565
|
+
|
|
1566
|
+
procedure SetInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty;
|
|
1567
|
+
const Value: IInterface);
|
|
1568
|
+
type
|
|
1569
|
+
TSetter = procedure(Value: IInterface) of object;
|
|
1570
|
+
TSetterWithIndex = procedure(Index: JSValue; Value: IInterface) of object;
|
|
1571
|
+
procedure setIntfP(Instance: TObject; const PropName: string; value: jsvalue); external name 'rtl.setIntfP';
|
|
1572
|
+
var
|
|
1573
|
+
sk: TSetterKind;
|
|
1574
|
+
Setter: String;
|
|
1575
|
+
begin
|
|
1576
|
+
if Propinfo.TypeInfo.Kind<>tkInterface then
|
|
1577
|
+
raise Exception.Create('Cannot set RAW interface from IInterface interface');
|
|
1578
|
+
sk:=GetPropSetterKind(PropInfo);
|
|
1579
|
+
Setter:=PropInfo.Setter;
|
|
1580
|
+
case sk of
|
|
1581
|
+
skNone:
|
|
1582
|
+
raise EPropertyError.CreateFmt(SCantWritePropertyS, [PropInfo.Name]);
|
|
1583
|
+
skField:
|
|
1584
|
+
setIntfP(Instance,Setter,Value);
|
|
1585
|
+
skProcedure:
|
|
1586
|
+
if (pfHasIndex and PropInfo.Flags)>0 then
|
|
1587
|
+
TSetterWithIndex(TJSObject(Instance)[Setter])(PropInfo.Index,Value)
|
|
1588
|
+
else
|
|
1589
|
+
TSetter(TJSObject(Instance)[Setter])(Value);
|
|
1590
|
+
skProcedureWithParams:
|
|
1591
|
+
raise EPropertyError.CreateFmt(SIndexedPropertyNeedsParams, [PropInfo.Name]);
|
|
1592
|
+
end;
|
|
1593
|
+
end;
|
|
1594
|
+
|
|
1595
|
+
function GetRawInterfaceProp(Instance: TObject; const PropName: string
|
|
1596
|
+
): Pointer;
|
|
1597
|
+
begin
|
|
1598
|
+
Result:=GetRawInterfaceProp(Instance,FindPropInfo(Instance,PropName));
|
|
1599
|
+
end;
|
|
1600
|
+
|
|
1601
|
+
function GetRawInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty
|
|
1602
|
+
): Pointer;
|
|
1603
|
+
begin
|
|
1604
|
+
Result:=Pointer(GetJSValueProp(Instance,PropInfo));
|
|
1605
|
+
end;
|
|
1606
|
+
|
|
1607
|
+
procedure SetRawInterfaceProp(Instance: TObject; const PropName: string;
|
|
1608
|
+
const Value: Pointer);
|
|
1609
|
+
begin
|
|
1610
|
+
SetRawInterfaceProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1611
|
+
end;
|
|
1612
|
+
|
|
1613
|
+
procedure SetRawInterfaceProp(Instance: TObject; PropInfo: TTypeMemberProperty;
|
|
1614
|
+
const Value: Pointer);
|
|
1615
|
+
begin
|
|
1616
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1617
|
+
end;
|
|
1618
|
+
|
|
1619
|
+
function SetToString(TypeInfo: TTypeInfo; Value: JSValue; Brackets: Boolean): String;
|
|
1620
|
+
var
|
|
1621
|
+
key, v: String;
|
|
1622
|
+
n: NativeInt;
|
|
1623
|
+
TIEnum: TTypeInfoEnum;
|
|
1624
|
+
TISet: TTypeInfoSet;
|
|
1625
|
+
begin
|
|
1626
|
+
Result:='';
|
|
1627
|
+
TISet:=TypeInfo as TTypeInfoSet;
|
|
1628
|
+
// get enum type if available
|
|
1629
|
+
TIEnum:=nil;
|
|
1630
|
+
if TISet.CompType is TTypeInfoEnum then
|
|
1631
|
+
TIEnum:=TTypeInfoEnum(TISet.CompType);
|
|
1632
|
+
// a set is a JS object, where included element is stored as: o[ElementDecimal]=true
|
|
1633
|
+
for Key in Value do
|
|
1634
|
+
begin
|
|
1635
|
+
n:=parseInt(Key,10);
|
|
1636
|
+
if (TIEnum<>nil) and (n>=TIEnum.MinValue) and (n<=TIEnum.MaxValue) then
|
|
1637
|
+
v:=TIEnum.EnumType.IntToName[n]
|
|
1638
|
+
else
|
|
1639
|
+
v:=str(n);
|
|
1640
|
+
if Result<>'' then Result:=Result+',';
|
|
1641
|
+
Result:=Result+v;
|
|
1642
|
+
end;
|
|
1643
|
+
if Brackets then
|
|
1644
|
+
Result:='['+Result+']';
|
|
1645
|
+
end;
|
|
1646
|
+
|
|
1647
|
+
function SetToString(PropInfo: TTypeMemberProperty; Value: JSValue; Brackets: Boolean): String;
|
|
1648
|
+
begin
|
|
1649
|
+
Result:=SetToString(PropInfo.TypeInfo, Value, Brackets);
|
|
1650
|
+
end;
|
|
1651
|
+
|
|
1652
|
+
function SetToString(PropInfo: TTypeMemberProperty; Value: JSValue): String;
|
|
1653
|
+
begin
|
|
1654
|
+
Result:=SetToString(PropInfo,Value,False);
|
|
1655
|
+
end;
|
|
1656
|
+
|
|
1657
|
+
function GetFloatProp(Instance: TObject; PropInfo: TTypeMemberProperty): Double;
|
|
1658
|
+
begin
|
|
1659
|
+
Result:=Double(GetJSValueProp(Instance,PropInfo));
|
|
1660
|
+
end;
|
|
1661
|
+
|
|
1662
|
+
function GetFloatProp(Instance: TObject; const PropName: string): Double;
|
|
1663
|
+
begin
|
|
1664
|
+
Result:=GetFloatProp(Instance,FindPropInfo(Instance,PropName));
|
|
1665
|
+
end;
|
|
1666
|
+
|
|
1667
|
+
procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Double
|
|
1668
|
+
);
|
|
1669
|
+
begin
|
|
1670
|
+
SetFloatProp(Instance,FindPropInfo(Instance,PropName),Value);
|
|
1671
|
+
end;
|
|
1672
|
+
|
|
1673
|
+
procedure SetFloatProp(Instance: TObject; PropInfo: TTypeMemberProperty;
|
|
1674
|
+
Value: Double);
|
|
1675
|
+
begin
|
|
1676
|
+
SetJSValueProp(Instance,PropInfo,Value);
|
|
1677
|
+
end;
|
|
1678
|
+
|
|
1679
|
+
end.
|
|
1680
|
+
|