Browse Source

* pos(...,...) overloads with variants, see tb0520.pp for the reason

git-svn-id: trunk@5770 -
florian 18 năm trước cách đây
mục cha
commit
28d59bbf6f
4 tập tin đã thay đổi với 88 bổ sung3 xóa
  1. 1 0
      .gitattributes
  2. 58 3
      rtl/inc/variant.inc
  3. 11 0
      rtl/inc/varianth.inc
  4. 18 0
      tests/tbs/tb0520.pp

+ 1 - 0
.gitattributes

@@ -6244,6 +6244,7 @@ tests/tbs/tb0516.pp svneol=native#text/plain
 tests/tbs/tb0517.pp svneol=native#text/plain
 tests/tbs/tb0518.pp svneol=native#text/plain
 tests/tbs/tb0519.pp svneol=native#text/plain
+tests/tbs/tb0520.pp svneol=native#text/plain
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 58 - 3
rtl/inc/variant.inc

@@ -117,12 +117,12 @@ function fpc_idispatch_to_variant(const i : idispatch) : variant;compilerproc;
   end;
 
 
-procedure fpc_dispinvoke_variant(dest : pvardata;const source : tvardata; 
+procedure fpc_dispinvoke_variant(dest : pvardata;const source : tvardata;
   calldesc : pcalldesc;params : pointer); compilerproc;
   begin
   	variantmanager.dispinvoke(dest,source,calldesc,params);
   end;
-       
+
 
 { ---------------------------------------------------------------------
     Overloaded operators.
@@ -948,7 +948,7 @@ operator :=(const source : terror) dest : olevariant;{$ifdef SYSTEMINLINE}inline
   begin
     variantmanager.olevarfromint(dest,source,-sizeof(terror));
   end;
-  
+
 
 function Unassigned: Variant; // Unassigned standard constant
 begin
@@ -980,3 +980,58 @@ end;
 procedure initvariantmanager;
   begin
   end;
+
+Function Pos (c : Char; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(c,ShortString(v));
+  end;
+
+
+Function Pos (s : ShortString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(s,ShortString(v));
+  end;
+
+
+Function Pos (a : AnsiString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(a,AnsiString(v));
+  end;
+
+
+Function Pos (w : WideString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(w,WideString(v));
+  end;
+
+
+Function Pos (v : Variant; Const c : Char) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(ShortString(v),c);
+  end;
+
+
+Function Pos (v : Variant; Const s : ShortString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(ShortString(v),s);
+  end;
+
+
+Function Pos (v : Variant; Const a : AnsiString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(AnsiString(v),a);
+  end;
+
+
+Function Pos (v : Variant; Const w : WideString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(WideString(v),w);
+  end;
+
+
+Function Pos (v1 : Variant; Const v2 : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+  begin
+    Result:=Pos(WideString(v1),WideString(v2));
+  end;
+
+

+ 11 - 0
rtl/inc/varianth.inc

@@ -442,6 +442,17 @@ operator :=(const source : currency) dest : olevariant;{$ifdef SYSTEMINLINE}inli
 operator :=(const source : tdatetime) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
 operator :=(const source : terror) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
 
+{ silly, but how else should the compiler know what to do with pos(<string type>,<variant>)? (FK) }
+Function Pos (c : Char; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (s : ShortString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (a : AnsiString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (w : WideString; Const v : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (v : Variant; Const c : Char) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (v : Variant; Const s : ShortString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (v : Variant; Const a : AnsiString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (v : Variant; Const w : WideString) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+Function Pos (v1 : Variant; Const v2 : Variant) : SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+
 {**********************************************************************
                              OLEVariant Operators
  **********************************************************************}

+ 18 - 0
tests/tbs/tb0520.pp

@@ -0,0 +1,18 @@
+uses
+  variants;
+var
+  w : widestring;
+  v : variant;
+  a : ansistring;
+begin
+  a:='';
+  w:='';
+  v:='asdf';
+  pos(a,v);
+  pos(w,v);
+  pos(v,v);
+  pos(v,a);
+  pos(v,w);
+  pos(v,v);
+end.
+