Переглянути джерело

+ support for tkUString in get/setpropvalue (mantis #14617)

git-svn-id: trunk@13829 -
Jonas Maebe 16 роки тому
батько
коміт
93171fdc23
3 змінених файлів з 53 додано та 0 видалено
  1. 1 0
      .gitattributes
  2. 23 0
      rtl/inc/variants.pp
  3. 29 0
      tests/webtbs/tw14617.pp

+ 1 - 0
.gitattributes

@@ -9316,6 +9316,7 @@ tests/webtbs/tw1451.pp svneol=native#text/plain
 tests/webtbs/tw14514.pp svneol=native#text/plain
 tests/webtbs/tw14536.pp svneol=native#text/plain
 tests/webtbs/tw14553.pp svneol=native#text/pascal
+tests/webtbs/tw14617.pp svneol=native#text/plain
 tests/webtbs/tw1470.pp svneol=native#text/plain
 tests/webtbs/tw1472.pp svneol=native#text/plain
 tests/webtbs/tw14740.pp svneol=native#text/plain

+ 23 - 0
rtl/inc/variants.pp

@@ -86,6 +86,8 @@ function VarToStr(const V: Variant): string;
 function VarToStrDef(const V: Variant; const ADefault: string): string;
 function VarToWideStr(const V: Variant): WideString;
 function VarToWideStrDef(const V: Variant; const ADefault: WideString): WideString;
+function VarToUnicodeStr(const V: Variant): UnicodeString;
+function VarToUnicodeStrDef(const V: Variant; const ADefault: UnicodeString): UnicodeString;
 
 {$ifndef FPUNONE}
 function VarToDateTime(const V: Variant): TDateTime;
@@ -2942,6 +2944,23 @@ begin
 end;
 
 
+function VarToUnicodeStr(const V: Variant): UnicodeString;
+
+begin
+  Result:=VarToUnicodeStrDef(V,'');
+end;
+
+
+function VarToUnicodeStrDef(const V: Variant; const ADefault: UnicodeString): UnicodeString;
+
+begin
+  If TVarData(V).vType<>varNull then
+    Result:=V
+  else
+    Result:=ADefault;
+end;
+
+
 {$ifndef FPUNONE}
 
 function VarToDateTime(const V: Variant): TDateTime;
@@ -4281,6 +4300,8 @@ begin
        Result := GetStrProp(Instance, PropInfo);
      tkWString:
        Result := GetWideStrProp(Instance, PropInfo);
+     tkUString:
+       Result := GetUnicodeStrProp(Instance, PropInfo);
      tkVariant:
        Result := GetVariantProp(Instance, PropInfo);
      tkInt64:
@@ -4355,6 +4376,8 @@ begin
          SetStrProp(Instance, PropInfo, VarToStr(Value));
        tkWString:
          SetWideStrProp(Instance, PropInfo, VarToWideStr(Value));
+       tkUString:
+         SetUnicodeStrProp(Instance, PropInfo, VarToUnicodeStr(Value));
        tkVariant:
          SetVariantProp(Instance, PropInfo, Value);
        tkInt64:

+ 29 - 0
tests/webtbs/tw14617.pp

@@ -0,0 +1,29 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+{$r-}
+uses
+  SysUtils, Classes, TypInfo, Variants;
+
+type
+  TBla = class(TPersistent)
+  private
+    fustr: unicodestring;
+  published
+    property ustr: unicodestring read fustr write fustr;
+  end;
+
+var
+  b: tbla;
+  u: unicodestring;
+begin
+  b:=tbla.create;
+  SetPropValue(b, 'ustr', 'abc');
+  if (b.ustr<>'abc') then
+    halt(1);
+  u:=getpropvalue(b,'ustr');
+  if (u<>'abc') then
+    halt(2);
+end.
+