Recent

Author Topic: TDoubleHelper, where is the round function?  (Read 1202 times)

jamie

  • Hero Member
  • *****
  • Posts: 6090
TDoubleHelper, where is the round function?
« on: March 23, 2019, 09:10:21 pm »

I wanted to use the DOUBLE helper to pretty up my code a bit but I noticed it does not have it?

is this the case or am I missing something ?

 I see it has a toon of other items I'll never use in my life time !

The only true wisdom is knowing you know nothing

furious programming

  • Hero Member
  • *****
  • Posts: 852
Re: TDoubleHelper, where is the round function?
« Reply #1 on: March 23, 2019, 09:53:51 pm »
TDoubleHelper does not have rounding method.
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TDoubleHelper, where is the round function?
« Reply #2 on: March 23, 2019, 10:24:41 pm »
I suppose I could overload the class and add it but that works only per unit unless I use a INC file.

maybe some time in the near future it could be thought about when the next release comes out.

The only true wisdom is knowing you know nothing

furious programming

  • Hero Member
  • *****
  • Posts: 852
Re: TDoubleHelper, where is the round function?
« Reply #3 on: March 24, 2019, 04:26:08 am »
An example of implementation:

Code: Pascal  [Select][+][-]
  1. {$MODESWITCH TYPEHELPERS}{$INLINE ON}
  2.  
  3. uses
  4.   SysUtils;
  5.  
  6. type
  7.   TDoubleHelper = type helper(SysUtils.TDoubleHelper) for Double
  8.   public
  9.     function Round(): Int64; inline;
  10.   end;
  11.  
  12.   function TDoubleHelper.Round(): Int64;
  13.   begin
  14.     Result := System.Round(Self);
  15.   end;

I suppose I could overload the class and add it but that works only per unit […]

Exactly, that's how the helpers work.

Quote
unless I use a INC file.

Don't do this. You still need to add one line of code in each unit, so it's better to have one helper instead of many the same (for the compiler it matters).
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018