Posted by webmaster Guido on March 14, 2003
In Reply to: Mph to Mps - this is what I have so far posted by MIKE on March
13, 2003 There are "MilesToMetres" metres in a mile, and there are 3600 seconds in an hour, so: For testing purposes, I made the program run in a repeat/until loop.
program Convert; {$APPTYPE CONSOLE} uses SysUtils; const MilesToMetres = 1606.344; var Mph, // miles per hour Mps: real; // metres per second S: string; // variable for Quit/Continue command begin repeat Write('Key in speed (mph): ') ; ReadLn(Mph); Mps := Mph * MilesToMetres / 3600; WriteLn('The speed in mps is ', Mps : 4 : 1); WriteLn('Q and ENTER = Quit, just ENTER = Continue'); Read(S); until UpperCase(S) = 'Q'; end. Additional notes for interested readers: Delphi is mainly used to write Windows applications with a graphical user interface (GUI), but you can also write "console applications", programs without a GUI. A console application runs in a "console window". The visual controls of the VCL are not used in console applications. Input and output are handled with commands such as Read, ReadLn, Write and WriteLn. In the example above, the source code for the console app is one single textfile, saved as CONVERT.DPR (there are no PAS files nor DFM files). Next it was compiled and tested in Delphi's IDE, just as any other Delphi application (menu Run / Run, or simply press F9). The line {$APPTYPE CONSOLE} in the source code tells Delphi that the file is to be compiled as a console application. The resulting executable is CONVERT.EXE and can be run from the command line (in old times known as a "MS-DOS prompt" or "DOS window").
|
Compiling Console Applications Learn Pascal with simple Delphi Console Applications |