mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-30 07:40:27 +02:00
rtl: fix SetPropValue/GetPropValue:
- raise a ERangeError in SetPropValue when passed value is out of property range - handle QWord values both in SetPropValue and GetPropValue git-svn-id: trunk@14500 -
This commit is contained in:
parent
9efa49b468
commit
c025471433
@ -4296,6 +4296,8 @@ begin
|
|||||||
Result := GetVariantProp(Instance, PropInfo);
|
Result := GetVariantProp(Instance, PropInfo);
|
||||||
tkInt64:
|
tkInt64:
|
||||||
Result := GetInt64Prop(Instance, PropInfo);
|
Result := GetInt64Prop(Instance, PropInfo);
|
||||||
|
tkQWord:
|
||||||
|
Result := QWord(GetInt64Prop(Instance, PropInfo));
|
||||||
else
|
else
|
||||||
raise EPropertyConvertError.CreateFmt('Invalid Property Type: %s',[PropInfo^.PropType^.Name]);
|
raise EPropertyConvertError.CreateFmt('Invalid Property Type: %s',[PropInfo^.PropType^.Name]);
|
||||||
end;
|
end;
|
||||||
@ -4306,10 +4308,12 @@ Procedure SetPropValue(Instance: TObject; const PropName: string; const Value:
|
|||||||
|
|
||||||
var
|
var
|
||||||
PropInfo: PPropInfo;
|
PropInfo: PPropInfo;
|
||||||
// TypeData: PTypeData;
|
TypeData: PTypeData;
|
||||||
O : Integer;
|
O: Integer;
|
||||||
S : String;
|
I64: Int64;
|
||||||
B : Boolean;
|
Qw: QWord;
|
||||||
|
S: String;
|
||||||
|
B: Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// find the property
|
// find the property
|
||||||
@ -4318,36 +4322,57 @@ begin
|
|||||||
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName])
|
raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName])
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
// TypeData := GetTypeData(PropInfo^.PropType);
|
TypeData := GetTypeData(PropInfo^.PropType);
|
||||||
// call Right SetxxxProp
|
// call Right SetxxxProp
|
||||||
case PropInfo^.PropType^.Kind of
|
case PropInfo^.PropType^.Kind of
|
||||||
tkBool:
|
tkBool:
|
||||||
begin
|
begin
|
||||||
{ to support the strings 'true' and 'false' }
|
{ to support the strings 'true' and 'false' }
|
||||||
B:=Value;
|
if (VarType(Value)=varOleStr) or
|
||||||
SetOrdProp(Instance, PropInfo, ord(B));
|
(VarType(Value)=varString) or
|
||||||
|
(VarType(Value)=varBoolean) then
|
||||||
|
begin
|
||||||
|
B:=Value;
|
||||||
|
SetOrdProp(Instance, PropInfo, ord(B));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
I64:=Value;
|
||||||
|
if (I64<TypeData^.MinValue) or (I64>TypeData^.MaxValue) then
|
||||||
|
raise ERangeError.Create(SRangeError);
|
||||||
|
SetOrdProp(Instance, PropInfo, I64);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
tkInteger, tkChar, tkWChar:
|
tkInteger, tkChar, tkWChar:
|
||||||
begin
|
begin
|
||||||
O:=Value;
|
I64:=Value;
|
||||||
SetOrdProp(Instance, PropInfo, O);
|
if (TypeData^.OrdType=otULong) then
|
||||||
|
if (I64<LongWord(TypeData^.MinValue)) or (I64>LongWord(TypeData^.MaxValue)) then
|
||||||
|
raise ERangeError.Create(SRangeError)
|
||||||
|
else
|
||||||
|
else
|
||||||
|
if (I64<TypeData^.MinValue) or (I64>TypeData^.MaxValue) then
|
||||||
|
raise ERangeError.Create(SRangeError);
|
||||||
|
SetOrdProp(Instance, PropInfo, I64);
|
||||||
end;
|
end;
|
||||||
tkEnumeration :
|
tkEnumeration :
|
||||||
begin
|
begin
|
||||||
if (VarType(Value)=varOleStr) or (VarType(Value)=varString) then
|
if (VarType(Value)=varOleStr) or (VarType(Value)=varString) then
|
||||||
begin
|
begin
|
||||||
S:=Value;
|
S:=Value;
|
||||||
SetEnumProp(Instance,PropInfo,S);
|
SetEnumProp(Instance,PropInfo,S);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
O:=Value;
|
I64:=Value;
|
||||||
SetOrdProp(Instance, PropInfo, O);
|
if (I64<TypeData^.MinValue) or (I64>TypeData^.MaxValue) then
|
||||||
|
raise ERangeError.Create(SRangeError);
|
||||||
|
SetOrdProp(Instance, PropInfo, I64);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
tkSet :
|
tkSet :
|
||||||
begin
|
begin
|
||||||
if (VarType(Value)=varOleStr) or (VarType(Value)=varString) then
|
if (VarType(Value)=varOleStr) or (VarType(Value)=varString) then
|
||||||
begin
|
begin
|
||||||
S:=Value;
|
S:=Value;
|
||||||
SetSetProp(Instance,PropInfo,S);
|
SetSetProp(Instance,PropInfo,S);
|
||||||
@ -4371,7 +4396,19 @@ begin
|
|||||||
tkVariant:
|
tkVariant:
|
||||||
SetVariantProp(Instance, PropInfo, Value);
|
SetVariantProp(Instance, PropInfo, Value);
|
||||||
tkInt64:
|
tkInt64:
|
||||||
SetInt64Prop(Instance, PropInfo, Value);
|
begin
|
||||||
|
I64:=Value;
|
||||||
|
if (I64<TypeData^.MinInt64Value) or (I64>TypeData^.MaxInt64Value) then
|
||||||
|
raise ERangeError.Create(SRangeError);
|
||||||
|
SetInt64Prop(Instance, PropInfo, I64);
|
||||||
|
end;
|
||||||
|
tkQWord:
|
||||||
|
begin
|
||||||
|
Qw:=Value;
|
||||||
|
if (Qw<TypeData^.MinQWordValue) or (Qw>TypeData^.MaxQWordValue) then
|
||||||
|
raise ERangeError.Create(SRangeError);
|
||||||
|
SetInt64Prop(Instance, PropInfo,Qw);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
raise EPropertyConvertError.CreateFmt('SetPropValue: Invalid Property Type %s',
|
raise EPropertyConvertError.CreateFmt('SetPropValue: Invalid Property Type %s',
|
||||||
[PropInfo^.PropType^.Name]);
|
[PropInfo^.PropType^.Name]);
|
||||||
|
Loading…
Reference in New Issue
Block a user