This sample demonstrates how to perform conversions from one measurement unit to another.
You can find the ConvertIt sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples and then navigate to either:
- Subversion Repository for Delphi: http://radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/branches/RadStudio_XE2/Delphi/RTL/ConvertIt/
- Subversion Repository for C++: http://radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/branches/RadStudio_XE2/CPP/RTL/ConvertIt/
This application creates a form with tabs for all registered conversion families: area, volume, temperature, and so on. For each conversion family, all the available units of measurement are displayed in the list box on the left. The user chooses a unit of measurement, specifies a quantity in the edit box, and the conversion results are displayed in the list box on the right of the form.
How to Use the Sample
- Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open ConvertIt.dproj.
- Press F9 or choose Run > Run.
The code for registering the Euro conversion class.
The code for the main form.
- TConvTypeEuroFactor is the conversion class used to convert currency to and from Euro. For more information, see Using a Class to Manage Conversions.
- TForm1 is the class for the main form of the application. It handles the display of the conversion families and types at run time and the conversion results.
- The conversion families tabs are added to the tab control component at run time in the OnShow event handler of the form. Likewise, the types for each family are added at run time in the OnChange event handler of the TTabControl component.
- The registered conversion families and types are retrieved with the GetConvFamilies and GetConvTypes functions, respectively.
- A TSpinEdit-like component is simulated by linking a TEdit and a TUpDown together using the TUpDown.Associate property.
- The TEdit component has an OnChange event handler attached, so that the values in the results list box change as the user types in a value.