Delphi Console如何清除最后一行内容
function ClearCurrentLine: boolean; const BUFSIZE = 0*0; var nConsoleHandle : Cardinal; lwWritten : Longword; Coord : TCoord; pcsb_info: _CONSOLE_SCREEN_BUFFER_INFO; dwConSize: Cardinal; begin Result := False; try nConsoleHandle := GetStdHandle(STD_OUTPUT_HANDLE); if GetConsoleScreenBufferInfo(nConsoleHandle, pcsb_info) then begin dwConSize := pcsb_info.dwSize.X * pcsb_info.dwSize.Y; //要清除的单元格数 =X*Y Coord.X := pcsb_info.dwCursorPosition.X; Coord.Y := pcsb_info.dwCursorPosition.Y-1; //只清除当前行就可以了 if not FillConsoleOutputCharacter(nConsoleHandle, #32, dwConSize, Coord, lwWritten) then //清空 Exit; SetConsoleCursorPosition(nConsoleHandle, Coord); end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end;
//https://docs.microsoft.com/zh-CN/windows/console/clearing-the-screen

浙公网安备 33010602011771号