unit Bindings.Converters;

interface
implementation
uses
  System.Bindings.Outputs,
  System.Rtti;


const
  IntToExtended = 'IntToExtended';
  ExtendedToInt = 'ExtendedToInt';


procedure RegisterConverters;
begin
  TValueRefConverterFactory.RegisterConversion([TypeInfo(Integer)], [TypeInfo(Extended)],
    TConverterDescription.Create(
      procedure(const I: TValue; var O: TValue)
      begin
        O := TValue.From<Extended>(I.AsInteger);
      end,

    IntToExtended, IntToExtended, '', True, '', nil)
  );

  TValueRefConverterFactory.RegisterConversion([TypeInfo(Extended)], [TypeInfo(Integer)],
    TConverterDescription.Create(
      procedure(const I: TValue; var O: TValue)
      begin
        O := TValue.From<Integer>(Trunc(I.AsExtended));
      end,

    ExtendedToInt, ExtendedToInt, '', True, '', nil)
  );
end;


initialization
  RegisterConverters;

end.
