본문 바로가기
Delphi Tip/+Tip

델파이 디버깅용 콘솔창 만들기

by MonoSoft 2023. 12. 11.
728x90
반응형

 

델파이 디버깅용 콘솔창 만들기

 



폼이 실행되면서 콘솔창을 한개 만든뒤, 폼위에 있는 마우스 좌표를
콘솔창에 실시간으로 출력하는 예이다


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
ConHwnd: THANDLE;
public
{ Public declarations }
procedure ConsoleLoad();
procedure ConsoleWriteLn(Str: string);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ConsoleLoad();
var
Chars : DWORD;
SBSize : _COORD;
begin
ConHwnd := CreateConsoleScreenBuffer(GENERIC_WRITE,
FILE_SHARE_WRITE,
nil,
CONSOLE_TEXTMODE_BUFFER,
nil );

SBSize.X := 80;
SBSize.Y := 1000;
SetConsoleScreenBufferSize(ConHwnd, SBSize);

SetConsoleActiveScreenBuffer(ConHwnd);
end;

procedure TForm1.ConsoleWriteLn(Str: string);
var
Chars : DWORD;
begin
SetConsoleTextAttribute(ConHwnd , 10);

Str := Str + #13#10;
WriteConsole(ConHwnd, @Str[1], Length(Str), Chars, nil);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
AllocConsole();
ConsoleLoad();
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeConsole();
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Str : string;
begin
Str := 'X:' + IntToStr(X) + ' Y:' + IntToStr(Y);
ConsoleWriteLn(Str);
end;

end.

728x90
반응형

댓글