tcnvstr3.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. { Type conversion program for char -> string }
  2. { possible types widechar -> widestring }
  3. { widechar -> shortstring }
  4. { widechar -> ansistring }
  5. { possible types char -> widestring }
  6. { char -> shortstring }
  7. { char -> ansistring }
  8. {$ifdef fpc}
  9. {$mode objfpc}
  10. {$ifndef ver1_0}
  11. {$define haswidestring}
  12. {$endif}
  13. {$else}
  14. {$ifndef ver70}
  15. {$define haswidestring}
  16. {$endif}
  17. {$endif}
  18. procedure fail;
  19. begin
  20. WriteLn('Failure!');
  21. halt(1);
  22. end;
  23. var
  24. str_ansi : ansistring;
  25. str_short : shortstring;
  26. {$ifdef haswidestring}
  27. str_wide : widestring;
  28. wc : widechar;
  29. {$endif haswidestring}
  30. c: char;
  31. _result : boolean;
  32. Begin
  33. {********************** char/widechar -> shortstring *******************}
  34. Write('widechar/char -> shortstring...');
  35. {* normal char *}
  36. _result := true;
  37. { empty string -> shortstring }
  38. str_short := '';
  39. if str_short <> '' then
  40. _result := false;
  41. { constant char -> shortstring }
  42. str_short := 'c';
  43. if str_short <> 'c' then
  44. _result := false;
  45. { normal char -> shortstring }
  46. str_short := '';
  47. c:='c';
  48. str_short:=c;
  49. if str_short <> 'c' then
  50. _result := false;
  51. {* wide char *}
  52. {$ifdef haswidestring}
  53. { constant char -> shortstring }
  54. str_short := shortstring(widechar('c'));
  55. if str_short <> 'c' then
  56. _result := false;
  57. {$endif}
  58. { wide char -> shortstring }
  59. { This should not compile - at least it does not compile under Delphi }
  60. { str_short := '';
  61. wc:='c';
  62. str_short:=wc;
  63. if str_short <> 'c' then
  64. _result := false;}
  65. if _result then
  66. WriteLn('Success!')
  67. else
  68. fail;
  69. {********************** char/widechar -> ansistring *******************}
  70. Write('widechar/char -> ansistring...');
  71. {* normal char *}
  72. _result := true;
  73. { empty string -> ansistring }
  74. str_ansi := '';
  75. if str_ansi <> '' then
  76. _result := false;
  77. { constant char -> ansistring }
  78. str_ansi := 'c';
  79. if str_ansi <> 'c' then
  80. _result := false;
  81. { normal char -> ansistring }
  82. str_ansi := '';
  83. c:='c';
  84. str_ansi:=c;
  85. if str_ansi <> 'c' then
  86. _result := false;
  87. {* wide char *}
  88. {$ifdef haswidestring}
  89. { constant char -> ansistring }
  90. str_ansi := widechar('c');
  91. if str_ansi <> 'c' then
  92. _result := false;
  93. { normal char -> ansistring }
  94. str_ansi := '';
  95. wc:='c';
  96. str_ansi:=wc;
  97. if str_ansi <> 'c' then
  98. _result := false;
  99. {$endif}
  100. if _result then
  101. WriteLn('Success!')
  102. else
  103. fail;
  104. {}
  105. {$ifdef haswidestring}
  106. {********************** char/widechar -> widestring *******************}
  107. Write('widechar/char -> widestring...');
  108. {* normal char *}
  109. _result := true;
  110. { empty string -> widestring }
  111. str_wide := '';
  112. if str_wide <> '' then
  113. _result := false;
  114. { constant char -> widestring }
  115. str_wide := 'c';
  116. if str_wide <> 'c' then
  117. _result := false;
  118. { normal char -> widestring }
  119. str_wide := '';
  120. c:='c';
  121. str_wide:=c;
  122. if str_wide <> 'c' then
  123. _result := false;
  124. {* wide char *}
  125. { constant char -> widestring }
  126. str_wide := widechar('c');
  127. if str_wide <> 'c' then
  128. _result := false;
  129. { normal char -> widestring }
  130. str_wide := '';
  131. wc:='c';
  132. str_wide:=wc;
  133. if str_wide <> 'c' then
  134. _result := false;
  135. if _result then
  136. WriteLn('Success!')
  137. else
  138. fail;
  139. {$endif haswidestring}
  140. end.