TssScaler is a non-visual component that simplifies conversion between two linear scales. Neither scale need be zero based.
The TssScalerRange object uses the terms minimum and maximum, but note that range checking is not performed (the minimum need not be less than the maximum). These terms are merely convenient to refer to two points that have a known value on both scales.
For example: to convert from Fahrenheit to Celsius, set the Scale1 minimum and maximum to 32 and 212 respectively, and the Scale2 minimum and maximum to 0 and 100. (These values are chosen because 32°F = 0°C, and 212°F = 100°C, but you can use any two sets of values that are known to be equivalent.) The Scale1ToScale2 function then takes a Fahrenheit value and returns the Celsius, and the Scale2ToScale1 function takes a Celsius value and returns the Fahrenheit.
Note: If you frequently use a Fahrenheit to Celsius version of this component as described above, or any other particular version, then it is probably better to derive a specific conversion component from TssCustomScaler. The complete code for TssFahrenheitToCelsius is illustrated here.
This method has the following advantages:
- the scale constants are fixed and cannot be inadvertently changed,
- the ScaleXToScaleY functions can be replaced by more meaningful equivalents, such as CtoF or even ConvertCelsiusToFahrenheit.
|Delphi 1||Delphi 2||Delphi 3||Delphi 4|
|Delphi 5||Delphi 6||Delphi 7||Delphi 8|
|Delphi 2005||Delphi 2006||Delphi 2007|
Download scaler.zip (5 KB)