1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

EnsureRange

unit
Math
category
range handling

declaration
function EnsureRange(const AValue, AMin, AMax: Integer): Integer; overload;
function EnsureRange(const AValue, AMin, AMax: Int64): Int64; overload;
function EnsureRange(const AValue, AMin, AMax: Double): Double; overload;

description
Returns the closest value to a specified value within a specified range

EnsureRange returns AValue if AMin <= AValue <= AMax.
EnsureRange returns AMin if AMin > AValue.
EnsureRange returns AMAx if AMax < AValue.

example
var  lt, in, gt : integer;

lt := -5; in := 0; gt := 5;

// EnsureRange(lt, -3, 3) = -3 
// EnsureRange(in, -3, 3) = 0 
// EnsureRange(gt, -3, 3) = 3 

in real code

see also
InRange,


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.