source: branches/Independent/SystemApi.pas

Last change on this file was 67, checked in by chronos, 3 weeks ago
  • Modified: Apps split into separate units.
  • Modified: SystemApi moved into separate unit.
File size: 2.1 KB
Line 
1unit SystemApi;
2
3interface
4
5uses
6 Classes, SysUtils, Api, Os, DateUtils;
7
8type
9 { TSystemApi }
10
11 TSystemApi = class(TApi)
12 private
13 FName: string;
14 FText: string;
15 procedure WriteLineSync;
16 procedure RunAppSync;
17 public
18 App: TRunningApp;
19 System: TSystem;
20 procedure WriteLine(Text: string); override;
21 procedure RunApp(Name: string); override;
22 procedure Sleep(Time: TDateTime); override;
23 function CreateWindow: THandle; override;
24 procedure SetWindowName(Handle: THandle; Name: string); override;
25 procedure SetWindowRect(Handle: THandle; Rect: TRect); override;
26 procedure SetWindowVisible(Handle: THandle; Visible: Boolean); override;
27 end;
28
29
30implementation
31
32{ TSystemApi }
33
34procedure TSystemApi.WriteLineSync;
35begin
36 System.Console.Write(App.App.Name + ': ' + FText);
37end;
38
39procedure TSystemApi.RunAppSync;
40begin
41 System.RunApp(FName);
42end;
43
44procedure TSystemApi.WriteLine(Text: string);
45begin
46 FText := Text;
47 TThread.Synchronize(App.AppThread, WriteLineSync);
48end;
49
50procedure TSystemApi.RunApp(Name: string);
51begin
52 FName := Name;
53 TThread.Synchronize(App.AppThread, RunAppSync);
54end;
55
56procedure TSystemApi.Sleep(Time: TDateTime);
57begin
58 App.AppThread.Sleep(Round(Time / OneMillisecond));
59end;
60
61function TSystemApi.CreateWindow: THandle;
62var
63 Window: TWindow;
64begin
65 Window := System.Windows.AddNew;
66 Window.Handle := System.Handles.AddNew;
67 Result := Window.Handle;
68end;
69
70procedure TSystemApi.SetWindowName(Handle: THandle; Name: string);
71var
72 Window: TWindow;
73begin
74 Window := System.Windows.SearchByHandle(Handle);
75 if Assigned(Window) then begin
76 Window.Name := Name;
77 System.Redraw;
78 end;
79end;
80
81procedure TSystemApi.SetWindowRect(Handle: THandle; Rect: TRect);
82var
83 Window: TWindow;
84begin
85 Window := System.Windows.SearchByHandle(Handle);
86 if Assigned(Window) then begin
87 Window.Rect := Rect;
88 System.Redraw;
89 end;
90end;
91
92procedure TSystemApi.SetWindowVisible(Handle: THandle; Visible: Boolean);
93var
94 Window: TWindow;
95begin
96 Window := System.Windows.SearchByHandle(Handle);
97 if Assigned(Window) then begin
98 Window.Visible := Visible;
99 System.Redraw;
100 end;
101end;
102
103end.
104
Note: See TracBrowser for help on using the repository browser.