On Sun, Feb 25, 2018 at 5:34 PM, Michael Van Canneyt
<mich...@freepascal.org> wrote:

>> So, would it be possible to have an overloaded Abs(V: Variant):
>> Variant; function in the variants unit?
>
>
> I advise against it.
>
> S : String;
>
> begin
>   S:='My very nice string';
>   S:=Abs(S);
> end;
>
> Will then compile and give a run-time error, as opposed to a compile-time
> error now.


Suggestion from the forum:
function Abs(var V: Variant): Variant; overload;
begin                                        ;
  If (VarIsNumeric(V)) then
  begin
    if V< 0 then
      Result := -V
    else
      Result := V
  end
  else
   Raise EVariantBadVarTypeError.Create(SomeMessage);
end;

While this will give hints if you did not initialize V, it will not
let you compile Abs(AString).

Bart
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to