home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / PASCAL / WINTL / WINTL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1994-09-12  |  6.8 KB  |  222 lines

  1. {****************************************}
  2. {*            WINTL.PAS 1.00            *}
  3. {*                                      *}
  4. {*       Author : Thomas Bargholz       *}
  5. {*    Written : September 12th, 1994    *}
  6. {*                                      *}
  7. {*    Donated to the Public Domain      *}
  8. {****************************************}
  9.  
  10. {
  11.  
  12. This unit gives you access to the country info on the PC running your
  13. application. It can give you information from DOS and from WIN.INI, as
  14. it's possible to set Windows to a country different to the DOS setting.
  15.  
  16. In CountryInfoRec the parameters return the following info:
  17.  
  18. CountryCode returns a code that indentifies the country. The possible
  19. country code are:
  20. $001 : US
  21. $002 : Canadien-French
  22. $003 : Latin America
  23. $01F : Netherlands
  24. $020 : Belgium
  25. $021 : France
  26. $022 : Spain
  27. $024 : Hungary
  28. $026 : Yugoslavia
  29. $027 : Italy
  30. $029 : Switzerland
  31. $02A : Tjekia (Czechoslovakia)
  32. $02B : Austria
  33. $02C : UK
  34. $02D : Denmark
  35. $02E : Sweden
  36. $02F : Norway
  37. $030 : Poland
  38. $031 : Germany
  39. $037 : Brazil
  40. $03D : International English (Australia in DR-DOS 5)
  41. $051 : Japan
  42. $052 : Korea
  43. $056 : China
  44. $058 : Taiwan
  45. $05A : Turkey
  46. $15F : Portugal
  47. $162 : Iceland
  48. $166 : Finland
  49. $311 : Middle East/Saudi Arabia
  50. $3CC : Israel
  51.  
  52. DateFormat returns a code for the type of date to display:
  53. 0 : US (mm-dd-yy)
  54. 1 : Europe (dd-mm-yy)
  55. 2 : Japan (yy-mm-dd)
  56.  
  57. TimeFormat returns a code for the type of time to display:
  58. 0 : 12h clock
  59. 1 : 24h clock
  60.  
  61. DateSeparator returns the char used to separate the different parts of
  62. a date. E.g "-" (dd-mm-yy) or "/" (dd/mm/yy)
  63.  
  64. TimeSeparator returns the char used to separate the different parts of
  65. a clock. E.g "." (hh.mm.ss) or ":" (hh:mm:ss)
  66.  
  67. CurrencySymbol is the symbol for the countrys currency.
  68.  
  69. ThousandSeparator is the char that separates the thousand in the numbers.
  70. E.g "," (1,000) or "." (1.000)
  71.  
  72. DecimalSeparator is the char that separates the decimal in the numbers.
  73. E.g "," (7,5) or "." (7.5)
  74.  
  75. DigitsAfterDecimal is the number of digits after decimal in the countrys
  76. currency.
  77.  
  78. If you have any comments, suggestions or bug reports, please contact me:
  79.  
  80. e-mail    : tba@m.dia.dk
  81. snail mail: Thomas Bargholz
  82.             Smallegade 20, 3 tv.
  83.             DK-2000 Frederiksberg
  84.             Denmark
  85. }
  86.  
  87.  
  88. Unit WIntl;
  89.  
  90. Interface
  91.  
  92. Type
  93.   CountryInfoRec = Record
  94.     CountryCode : Word; {Country code for the currentcountry}
  95.     DateFormat : Word; {Format for date (US/Europe/Japan)}
  96.     TimeFormat : Word; {Time format (12h/24h)}
  97.     DateSeparator : Array[0..1] Of Char;  {Char to separate date entries (d,m,y)}
  98.     TimeSeparator : Array[0..1] Of Char;  {Char to separate time entries (h,m,s)}
  99.     CurrencySymbol : Array[0..3] Of Char; {Currency symbol (e.g $ or £)}
  100.     ThousandSeparator : Array[0..1] Of Char; {Char to separate thousands in numbers}
  101.     DecimalSeparator : Array[0..1] Of Char; {Char to separate decimal in numbers}
  102.     DigitsAfterDecimal : Byte; {Number of digits after decimal in currency}
  103.   End;
  104.  
  105. Type
  106.   TSource = (DOS, WIN);
  107.  
  108. Procedure GetDOSCountryInfo(Var CIR : CountryInfoRec);
  109.    {- Return the country information from DOS}
  110.  
  111. Procedure GetWinCountryInfo(Var CIR : CountryInfoRec);
  112.    {- Return the country info from WIN.INI}
  113.  
  114. Function CountryAsString(Code : Word; Source : TSource) : PChar;
  115.    {- Return the country as a string. Source can be either
  116.       DOS or WIN, to determine where to get the info from}
  117.  
  118. Implementation
  119.  
  120. Uses
  121.   WinProcs,
  122.   WinDOS,
  123.   Strings;
  124.  
  125. Procedure GetDosCountryInfo(Var CIR : CountryInfoRec);
  126. Var
  127.   Regs : TRegisters;
  128.   CountryInfo : Array[0..33] Of Byte;
  129.   I : Integer;
  130. Begin
  131.   With Regs Do
  132.   Begin
  133.     AX := $3800;
  134.     DX := Ofs(CountryInfo);
  135.     DS := Seg(CountryInfo);
  136.     MsDos(Regs);
  137.     CIR.CountryCode := BX;
  138.   End;
  139.   With CIR Do
  140.   Begin
  141.     DateFormat := Word(CountryInfo[1]) Shl 8 + CountryInfo[0];
  142.     DateSeparator[0] := Char(CountryInfo[11]);
  143.     If (CountryInfo[17] And $01) = $00 Then
  144.       TimeFormat := 0
  145.     Else
  146.       TimeFormat := 1;
  147.     TimeSeparator[0] := Char(CountryInfo[13]);
  148.     For I := 0 To 3 Do
  149.       CurrencySymbol[I] := Char(CountryInfo[2+I]);
  150.     ThousandSeparator[0] := Char(CountryInfo[7]);
  151.     DecimalSeparator[0] := Char(CountryInfo[9]);
  152.     DigitsAfterDecimal := CountryInfo[16];
  153.   End;
  154. End;
  155.  
  156. Procedure GetWinCountryInfo(Var CIR : CountryInfoRec);
  157. Var
  158.   Return : Integer;
  159. Begin
  160.   With CIR Do
  161.   Begin
  162.     CountryCode := GetProfileInt('intl','iCountry',1);
  163.     DateFormat := GetProfileInt('intl','iDate',0);
  164.     TimeFormat := GetProfileInt('intl','iTime',0);
  165.     Return := GetProfileString('intl','sDate','/',DateSeparator,2);
  166.     Return := GetProfileString('intl','sTime',':',TimeSeparator,2);
  167.     Return := GetProfileString('intl','sCurrency', '$', CurrencySymbol, 4);
  168.     Return := GetProfileString('intl', 'sThousand', ',', ThousandSeparator, 2);
  169.     Return := GetProfileString('intl', 'sDecimal', '.', DecimalSeparator, 2);
  170.     DigitsAfterDecimal := GetProfileInt('intl', 'iDigits', 2);
  171.   End;
  172. End;
  173.  
  174. Function CountryAsString(Code : Word; Source : TSource) : PChar;
  175. Var
  176.   S : Array[0..47] Of Char;
  177.   Return : Integer;
  178. Begin
  179.   If Source = WIN Then
  180.   Begin
  181.     Return := GetProfileString('intl', 'sCountry', 'International English', S, 48);
  182.     CountryAsString := S;
  183.   End
  184.   Else
  185.     Case Code Of
  186.       $001 : CountryAsString := 'US';
  187.       $002 : CountryAsString := 'Canadien-French';
  188.       $003 : CountryAsString := 'Latin America';
  189.       $01F : CountryAsString := 'Netherlands';
  190.       $020 : CountryAsString := 'Belgium';
  191.       $021 : CountryAsString := 'France';
  192.       $022 : CountryAsString := 'Spain';
  193.       $024 : CountryAsString := 'Hungary';
  194.       $026 : CountryAsString := 'Yugoslavia';
  195.       $027 : CountryAsString := 'Italy';
  196.       $029 : CountryAsString := 'Switzerland';
  197.       $02A : CountryAsString := 'Tjekia'; {What used to be Czechoslovakia}
  198.       $02B : CountryAsString := 'Austria';
  199.       $02C : CountryAsString := 'UK';
  200.       $02D : CountryAsString := 'Denmark';
  201.       $02E : CountryAsString := 'Sweden';
  202.       $02F : CountryAsString := 'Norway';
  203.       $030 : CountryAsString := 'Poland';
  204.       $031 : CountryAsString := 'Germany';
  205.       $037 : CountryAsString := 'Brazil';
  206.       $03D : CountryAsString := 'International English'; {Australia in DR-DOS 5}
  207.       $051 : CountryAsString := 'Japan';
  208.       $052 : CountryAsString := 'Korea';
  209.       $056 : CountryAsString := 'China';
  210.       $058 : CountryAsString := 'Taiwan';
  211.       $05A : CountryAsString := 'Turkey';
  212.       $15F : CountryAsString := 'Portugal';
  213.       $162 : CountryAsString := 'Iceland';
  214.       $166 : CountryAsString := 'Finland';
  215.       $311 : CountryAsString := 'Middle East/Saudi Arabia';
  216.       $3CC : CountryAsString := 'Israel';
  217.     Else
  218.       CountryAsString := 'Unknown';
  219.     End;
  220. End;
  221.  
  222. End.