program cgapp;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp, ptcGraph, DControls, Events, UEvIntf
{ you can add units after this };
type
{ TConApplication }
TConApplication =
class(TCustomApplication)
protected
procedure DoRun;
override;
public
constructor Create(TheOwner: TComponent);
override;
destructor Destroy;
override;
procedure WriteHelp;
virtual;
end;
{ TTestControl }
TTestControl =
class(TCustomControl)
constructor Create(AOwner: TComponent);
procedure KeyDown(Sender: TObject; Key: Word; Shift: TShiftState);
override;
procedure KeyUp(Sender: TObject; Key: Word; Shift: TShiftState);
override;
procedure KeyPress(Sender: TObject; Key: Char);
override;
procedure MouseDown(Sender: TObject; Buttons: TMouseButtons; Shift: TShiftState; X,Y: Integer);
override;
procedure MouseUp(Sender: TObject; Buttons: TMouseButtons; Shift: TShiftState; X,Y: Integer);
override;
procedure MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
override;
end;
var
AControl: TTestControl;
constructor TTestControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure TTestControl.KeyDown(Sender: TObject; Key: Word; Shift: TShiftState);
begin
if Lo(Key)=27
then TCustomApplication(Owner).Terminate;
inherited KeyDown(Sender, Key, Shift);
end;
procedure TTestControl.KeyUp(Sender: TObject; Key: Word; Shift: TShiftState);
begin
if Lo(Key)=27
then TCustomApplication(Owner).Terminate;
inherited KeyUp(Sender, Key, Shift);
end;
procedure TTestControl.KeyPress(Sender: TObject; Key: Char);
begin
if Key = #27
then TCustomApplication(Owner).Terminate;
inherited KeyPress(Sender, Key);
end;
procedure TTestControl.MouseDown(Sender: TObject; Buttons: TMouseButtons;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Sender, Buttons, Shift, X, Y);
end;
procedure TTestControl.MouseUp(Sender: TObject; Buttons: TMouseButtons;
Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Sender, Buttons, Shift, X, Y);
end;
procedure TTestControl.MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
inherited MouseMove(Sender, Shift, X, Y);
end;
{ TConApplication }
procedure TConApplication.DoRun;
var
ErrorMsg:
String;
Event: TDCLEvent;
begin
// quick check parameters
ErrorMsg:=CheckOptions('
h','
help');
if ErrorMsg<>'
'
then begin
ShowException(
Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('
h','
help')
then begin
WriteHelp;
Terminate;
Exit;
end;
{ add your program here }
AControl := TTestControl.Create(self);
repeat
GetMyEvent(Event);
AControl.DispatchSingleEvent(Event);
until Terminated;
// stop program loop
//Terminate;
end;
constructor TConApplication.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TConApplication.Destroy;
begin
inherited Destroy;
end;
procedure TConApplication.WriteHelp;
begin
{ add your help code here }
writeln('
Usage: ',ExeName,'
-h');
end;
var
Application: TConApplication;
begin
Application:=TConApplication.Create(
nil);
Application.Title:='
Console Show-Events Application';
Application.Run;
Application.Free;
end.