source: branches/Independent/Forms/FormMain.pas

Last change on this file was 68, checked in by chronos, 7 months ago
  • Added: Mouse API support.
File size: 2.6 KB
Line 
1unit FormMain;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
7 ActnList, ExtCtrls, Os, FormConsole, FormScreen;
8
9type
10
11 { TFormName }
12
13 TFormName = class(TForm)
14 AConsole: TAction;
15 AFullscreen: TAction;
16 AExit: TAction;
17 ActionList1: TActionList;
18 MainMenu1: TMainMenu;
19 MenuItem1: TMenuItem;
20 MenuItem2: TMenuItem;
21 MenuItem3: TMenuItem;
22 MenuItem4: TMenuItem;
23 MenuItem5: TMenuItem;
24 MenuItemView: TMenuItem;
25 procedure AConsoleExecute(Sender: TObject);
26 procedure AExitExecute(Sender: TObject);
27 procedure AFullscreenExecute(Sender: TObject);
28 procedure FormCreate(Sender: TObject);
29 procedure FormDestroy(Sender: TObject);
30 procedure FormShow(Sender: TObject);
31 private
32 FileSystemDir: string;
33 System: TSystem;
34 procedure ConsoleWrite(Text: string);
35 function LoadFile(Name: string): string;
36 function GetMousePosition: TPoint;
37 public
38 FormConsole: TFormConsole;
39 FormScreen: TFormScreen;
40 end;
41
42var
43 FormName: TFormName;
44
45
46implementation
47
48{$R *.lfm}
49
50{ TFormName }
51
52procedure TFormName.FormShow(Sender: TObject);
53begin
54 FormScreen.ManualDock(Self, nil, alClient);
55 FormScreen.Align := alClient;
56 FormScreen.Show;
57
58 System := TSystem.Create;
59 System.Console.OnWrite := ConsoleWrite;
60 System.FileSystem.OnLoadFile := LoadFile;
61 System.Mouse.OnGetPosition := GetMousePosition;
62 System.OnDraw := FormScreen.Redraw;
63 FormScreen.System := System;
64
65 System.Start;
66end;
67
68procedure TFormName.FormCreate(Sender: TObject);
69begin
70 FileSystemDir := 'FileSystem';
71 FormConsole := TFormConsole.Create(nil);
72 FormScreen := TFormScreen.Create(nil);
73end;
74
75procedure TFormName.FormDestroy(Sender: TObject);
76begin
77 FreeAndNil(System);
78 FreeAndNil(FormConsole);
79 FreeAndNil(FormScreen);
80end;
81
82procedure TFormName.AExitExecute(Sender: TObject);
83begin
84 Close;
85 Application.Terminate;
86end;
87
88procedure TFormName.AConsoleExecute(Sender: TObject);
89begin
90 FormConsole.Show;
91end;
92
93procedure TFormName.AFullscreenExecute(Sender: TObject);
94begin
95
96end;
97
98procedure TFormName.ConsoleWrite(Text: string);
99begin
100 FormConsole.Memo1.Lines.Add(Text);
101end;
102
103function TFormName.LoadFile(Name: string): string;
104var
105 F: TFileStream;
106begin
107 F := TFileStream.Create(FileSystemDir + DirectorySeparator + Name, fmOpenRead);
108 try
109 if F.Size > 0 then begin
110 Result := default(string);
111 SetLength(Result, F.Size);
112 F.Read(Result[1], F.Size);
113 end else Result := '';
114 finally
115 F.Free;
116 end;
117end;
118
119function TFormName.GetMousePosition: TPoint;
120begin
121 Result := Mouse.CursorPos;
122end;
123
124end.
125
Note: See TracBrowser for help on using the repository browser.