Browse Source

* also support variants for %s in sysutils.format (mantis #16787)

git-svn-id: trunk@15509 -
Jonas Maebe 15 years ago
parent
commit
7d27f4c21d
3 changed files with 40 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 5 2
      rtl/objpas/sysutils/sysformt.inc
  3. 34 0
      tests/webtbs/tw16787.pp

+ 1 - 0
.gitattributes

@@ -10521,6 +10521,7 @@ tests/webtbs/tw16757.pp svneol=native#text/plain
 tests/webtbs/tw1677.pp svneol=native#text/plain
 tests/webtbs/tw1677.pp svneol=native#text/plain
 tests/webtbs/tw16770.pp svneol=native#text/plain
 tests/webtbs/tw16770.pp svneol=native#text/plain
 tests/webtbs/tw16772.pp svneol=native#text/plain
 tests/webtbs/tw16772.pp svneol=native#text/plain
+tests/webtbs/tw16787.pp svneol=native#text/plain
 tests/webtbs/tw16803.pp svneol=native#text/plain
 tests/webtbs/tw16803.pp svneol=native#text/plain
 tests/webtbs/tw1681.pp svneol=native#text/plain
 tests/webtbs/tw1681.pp svneol=native#text/plain
 tests/webtbs/tw16820.pp svneol=native#text/plain
 tests/webtbs/tw16820.pp svneol=native#text/plain

+ 5 - 2
rtl/objpas/sysutils/sysformt.inc

@@ -298,8 +298,11 @@ begin
                   if CheckArg(vtWidestring,false) then
                   if CheckArg(vtWidestring,false) then
                     hs:=WideString(Args[doarg].VWideString)
                     hs:=WideString(Args[doarg].VWideString)
                 else
                 else
-                  if CheckArg(vtAnsiString,true) then
-                    hs:=ansistring(Args[doarg].VAnsiString);
+                  if CheckArg(vtAnsiString,false) then
+                    hs:=ansistring(Args[doarg].VAnsiString)
+                else
+                  if CheckArg(vtVariant,true) then
+                    hs:=Args[doarg].VVariant^;
                 Index:=Length(hs);
                 Index:=Length(hs);
                 If (Prec<>-1) and (Index>Prec) then
                 If (Prec<>-1) and (Index>Prec) then
                   Index:=Prec;
                   Index:=Prec;

+ 34 - 0
tests/webtbs/tw16787.pp

@@ -0,0 +1,34 @@
+{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
+uses
+  Variants, SysUtils;
+
+var
+  v: Variant;
+  code: integer;
+
+begin
+  code := 0;
+  v := 10;
+  try
+    writeln(Format('%s', [v]));
+  except
+    ShowException(exceptObject, exceptAddr);
+    code := code or 1;
+  end;  
+  v := 'foo';
+  try
+    writeln(Format('%s', [v]));
+  except
+    ShowException(exceptObject, exceptAddr);
+    code := code or 2;
+  end;  
+  v := 1.5;
+  try
+    writeln(Format('%s', [v]));
+  except
+    ShowException(exceptObject, exceptAddr);
+    code := code or 4;
+  end;
+  Halt(code);
+end.
+