source: branches/Independent/Api.pas

Last change on this file was 66, checked in by chronos, 6 weeks ago
  • Added: Api calls to show windows.
File size: 1.6 KB
Line 
1unit Api;
2
3interface
4
5uses
6 Classes, SysUtils, Generics.Collections;
7
8type
9 THandle = NativeInt;
10
11 { THandles }
12
13 THandles = class(TList<THandle>)
14 NewHandle: THandle;
15 function AddNew: THandle;
16 end;
17
18 { TApi }
19
20 TApi = class
21 procedure WriteLine(Text: string); virtual; abstract;
22 procedure RunApp(Name: string); virtual; abstract;
23 procedure Sleep(Time: TDateTime); virtual; abstract;
24 function CreateWindow: THandle; virtual; abstract;
25 procedure SetWindowName(Handle: THandle; Name: string); virtual; abstract;
26 procedure SetWindowRect(Handle: THandle; Rect: TRect); virtual; abstract;
27 procedure SetWindowVisible(Handle: THandle; Visible: Boolean); virtual; abstract;
28 end;
29
30 TAppContext = class
31 Api: TApi;
32 end;
33
34 { TApp }
35
36 TApp = class
37 Name: string;
38 procedure Run(Context: TAppContext); virtual; abstract;
39 constructor Create; virtual;
40 end;
41
42 TAppClass = class of TApp;
43
44 { TApps }
45
46 TApps = class(TObjectList<TApp>)
47 function AddNew(AppClass: TAppClass): TApp;
48 function SearchByName(Name: string): TApp;
49 end;
50
51
52implementation
53
54{ THandles }
55
56function THandles.AddNew: THandle;
57begin
58 Result := NewHandle;
59 Inc(NewHandle);
60 Add(Result);
61end;
62
63{ TApp }
64
65constructor TApp.Create;
66begin
67end;
68
69{ TApps }
70
71function TApps.AddNew(AppClass: TAppClass): TApp;
72begin
73 Result := AppClass.Create;
74 Add(Result);
75end;
76
77function TApps.SearchByName(Name: string): TApp;
78var
79 I: Integer;
80begin
81 I := 0;
82 while (I < Count) and (Items[I].Name <> Name) do Inc(I);
83 if I < Count then Result := Items[I]
84 else Result := nil;
85end;
86
87
88end.
89
Note: See TracBrowser for help on using the repository browser.