Line | |
---|
1 | unit Api;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
52 | implementation
|
---|
53 |
|
---|
54 | { THandles }
|
---|
55 |
|
---|
56 | function THandles.AddNew: THandle;
|
---|
57 | begin
|
---|
58 | Result := NewHandle;
|
---|
59 | Inc(NewHandle);
|
---|
60 | Add(Result);
|
---|
61 | end;
|
---|
62 |
|
---|
63 | { TApp }
|
---|
64 |
|
---|
65 | constructor TApp.Create;
|
---|
66 | begin
|
---|
67 | end;
|
---|
68 |
|
---|
69 | { TApps }
|
---|
70 |
|
---|
71 | function TApps.AddNew(AppClass: TAppClass): TApp;
|
---|
72 | begin
|
---|
73 | Result := AppClass.Create;
|
---|
74 | Add(Result);
|
---|
75 | end;
|
---|
76 |
|
---|
77 | function TApps.SearchByName(Name: string): TApp;
|
---|
78 | var
|
---|
79 | I: Integer;
|
---|
80 | begin
|
---|
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;
|
---|
85 | end;
|
---|
86 |
|
---|
87 |
|
---|
88 | end.
|
---|
89 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.