-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelphiInputOutputUTF8.dpr
More file actions
36 lines (29 loc) · 1.35 KB
/
DelphiInputOutputUTF8.dpr
File metadata and controls
36 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
program DelphiInputOutputUTF8;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
VAR
NumCharsWritten: DWORD;
NumCharsRead: DWORD;
Text: String; // Строка UTF-8
i: integer;
begin
try
SetLength(Text, 255); // Устанавливаем максимальное количество символов для переменной
// Вводим строку в UTF-8 через вызов функции WinAPI ReadConsoleW
ReadConsole(GetStdHandle(STD_INPUT_HANDLE), PChar(Text), Length(Text), NumCharsRead, nil);
SetLength(Text, NumCharsRead - 2); // Убираем с ввода символы новой строки (нажатие на Enter)
// Распечатаем символы на экран
for i := 1 to Length(Text) do begin
Writeln('[', i, '] char: ', Text[i], ', code: ', ord(Text[i]));
end;
// Меняем текст UTF-8 (добавляем в конец)
Text := Text + ' -> Замечательно! Das ist großartig! Wonderful! 精彩的! رائع!';
// Выводим строку в UTF-8 через вызов функции WinAPI WriteConsoleW
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), PChar(Text), Length(Text), NumCharsWritten, nil);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
ReadLn; // Ожидание нажатия на Enter
end.