mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-09 01:56:06 +02:00
rtl: typinfo: GetOrdProp/SetOrdProp for tkSet
This commit is contained in:
parent
cff1e9dde9
commit
9636f88afa
@ -895,24 +895,51 @@ end;
|
|||||||
|
|
||||||
function GetOrdProp(Instance: TObject; const PropName: String): longint;
|
function GetOrdProp(Instance: TObject; const PropName: String): longint;
|
||||||
begin
|
begin
|
||||||
Result:=longint(GetJSValueProp(Instance,PropName));
|
Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
function GetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty
|
||||||
): longint;
|
): longint;
|
||||||
|
var
|
||||||
|
o: TJSObject;
|
||||||
|
Key: String;
|
||||||
|
n: NativeInt;
|
||||||
begin
|
begin
|
||||||
Result:=longint(GetJSValueProp(Instance,PropInfo));
|
if PropInfo.TypeInfo.Kind=tkSet then
|
||||||
|
begin
|
||||||
|
// a set is a JS object, with the following property: o[ElementDecimal]=true
|
||||||
|
o:=TJSObject(GetJSValueProp(Instance,PropInfo));
|
||||||
|
Result:=0;
|
||||||
|
for Key in o do
|
||||||
|
begin
|
||||||
|
n:=parseInt(Key,10);
|
||||||
|
if n<32 then
|
||||||
|
Result:=Result+(1 shl n);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
Result:=longint(GetJSValueProp(Instance,PropInfo));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetOrdProp(Instance: TObject; const PropName: String; Value: longint);
|
procedure SetOrdProp(Instance: TObject; const PropName: String; Value: longint);
|
||||||
begin
|
begin
|
||||||
SetJSValueProp(Instance,PropName,Value);
|
SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
procedure SetOrdProp(Instance: TObject; const PropInfo: TTypeMemberProperty;
|
||||||
Value: longint);
|
Value: longint);
|
||||||
|
var
|
||||||
|
o: TJSObject;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
SetJSValueProp(Instance,PropInfo,Value);
|
if PropInfo.TypeInfo.Kind=tkSet then
|
||||||
|
begin
|
||||||
|
o:=TJSObject.new;
|
||||||
|
for i:=0 to 31 do
|
||||||
|
if (1 shl i) and Value>0 then
|
||||||
|
o[str(i)]:=true;
|
||||||
|
SetJSValueProp(Instance,PropInfo,o);
|
||||||
|
end else
|
||||||
|
SetJSValueProp(Instance,PropInfo,Value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetEnumProp(Instance: TObject; const PropName: String): String;
|
function GetEnumProp(Instance: TObject; const PropName: String): String;
|
||||||
|
Loading…
Reference in New Issue
Block a user