home *** CD-ROM | disk | FTP | other *** search
- {: Extra Routines for ESBCalc - these are taken from our internal library.
- This unit requires Delphi 4
-
- (c) 1999 ESB Consultancy <p>
-
- These routines are used by ESB Consultancy within the
- development of their Customised Application. <p>
-
- ESB Consultancy retains full copyright. <p>
-
- ESB Consultancy grants users of this code royalty free rights
- to do with this code as they wish. <p>
-
- ESB Consultancy makes no guarantees nor excepts any liabilities
- due to the use of these routines. <p>
-
- We do ask that if this code helps you in you development
- that you send as an email mailto:esb@gold.net.au or even
- a local postcard. It would also be nice if you gave us a
- mention in your About Box or Help File. <p>
-
- ESB Consultancy Home Page: http://www.gold.net.au/~esb <p>
-
- Mail Address: PO Box 2259, Boulder, WA 6432 AUSTRALIA <p>
- }
-
- unit ESBExtra;
-
- interface
-
- // Virtual Keys that Delphi omitted
- const
- VK_0 = 48;
- VK_1 = 49;
- VK_2 = 50;
- VK_3 = 51;
- VK_4 = 52;
- VK_5 = 53;
- VK_6 = 54;
- VK_7 = 55;
- VK_8 = 56;
- VK_9 = 57;
-
- const
- VK_A = 65;
- VK_B = 66;
- VK_C = 67;
- VK_D = 68;
- VK_E = 69;
- VK_F = 70;
- VK_G = 71;
- VK_H = 72;
- VK_I = 73;
- VK_J = 74;
- VK_K = 75;
- VK_L = 76;
- VK_M = 77;
- VK_N = 78;
- VK_O = 79;
- VK_P = 80;
- VK_Q = 81;
- VK_R = 82;
- VK_S = 83;
- VK_T = 84;
- VK_U = 85;
- VK_V = 86;
- VK_W = 87;
- VK_X = 88;
- VK_Y = 89;
- VK_Z = 90;
-
- //: Dynamic Arrays used in the Calculator
- type
- TDynFloatArray = array of Extended;
- TDynCharArray = array of Char;
-
- {: Returns the substring consisting of the first N characters of S.
- If N > Length (S) then the substring = S. }
- function LeftStr (const S : string; const N : Integer): string;
-
- {: Converts a String into an Extended Real }
- function Str2Ext (const S: String): Extended;
-
- {: Converts an Extended Real into an exact String, No padding,
- with given number of Decimal Places }
- function Ext2EStr (const E: Extended; const Decimals: Byte): String;
-
- {: Converts an Extended Real into an exact String, No padding,
- with given number of Decimal Places, with "Commas" separating
- thousands }
- function Ext2CEStr (const E: Extended; const Decimals: Byte): String;
-
- {: Removes all Thousand's Separators from a string }
- function StripThousandSep (const S: string): string;
-
- implementation
-
- uses
- SysUtils;
-
- function LeftStr (const S : string; const N : Integer): string;
- begin
- Result := Copy (S, 1, N);
- end;
-
- function Str2Ext (const S: String): Extended;
- var
- S2: string;
- begin
- try
- S2 := StripThousandSep (S);
- Result := StrToFloat (S2);
- except
- Result := 0;
- end;
- end;
-
- function Ext2EStr (const E: Extended; const Decimals: Byte): String;
- begin
- try
- Result := FloatToStrF (E, ffFixed, 18, Decimals)
- except
- Result := '';
- end;
- end;
-
- function Ext2CEStr (const E: Extended; const Decimals: Byte): String;
- begin
- try
- Result := FloatToStrF (E, ffNumber, 18, Decimals)
- except
- Result := '';
- end;
- end;
-
- function StripThousandSep (const S: string): string;
- var
- P: Integer;
- begin
- Result := S;
- repeat
- P := Pos (ThousandSeparator, Result);
- if P > 0 then
- Result := LeftStr (Result, P - 1) + Copy (Result, P + 1,
- Length (Result) - P);
- until P = 0;
- end;
-
- end.
-