Re: Delphi Pro 5 Math UnitPosted by webmaster Guido on April 09, 2002 at 19:51:36: In Reply to: Delphi Pro 5 Math Unit posted by Lionel Joyner p12219 on March 27, 2002 at 18:28:34:
: Need help with the Delphi Pro 5 MATH UNIT. I understand that it exist but have not found any books or anyone that can tell me how to set it up and use it. --------- For the functions Sin() and Cos you don't need the Math-unit. But because for all trigonometric functions you must expressed the angles in radians, you need the function DegToRad(), and that one is in the Math-unit. Starting with Delphi 4, every version has the Math unit (it was not included in the Standard edition of D2 nor D3, only the Professional and Client/Server versions had the Math unit). Attention: the Math-unit isn't included by default in the template of a new form, so you have to add it yourself to the "uses" directive on top of the unit. For example, if it says:
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; then you have to change it to:
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, MATH; Below is some code to play with. The degrees, minutes and seconds are entered in the TEdit-boxes editDeg, editMin and editSec. Note that I omitted all error checking just to make the code clearer, but in a real application you have to check if the edit-boxes contain valid integer values.
procedure TForm1.btnCalculateClick(Sender: TObject); var Deg, Min, Sec: integer; D, R, S, C: real; begin Deg := StrToInt(editDeg.Text); Min := StrToInt(editMin.Text); Sec := StrToInt(editSec.Text); D := Deg + Min / 60 + Sec / 3600; // degrees plus decimal fraction R := DegToRad(D); // convert degrees to radians S := Sin(R); C := Cos(R); labelDegDec.Caption := FloatToStr(D); labelRad.Caption := FloatToStr(R); labelSin.Caption := FloatToStr(S); labelCos.Caption := FloatToStr(C); end;
|
|