1 | unit UMainForm;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, StdCtrls, ComCtrls, UVirtualMachine;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TProgramEdit = class(TCustomControl)
|
---|
11 | Code: TStringList;
|
---|
12 | procedure Paint; override;
|
---|
13 | constructor Create(AOwner: TComponent); override;
|
---|
14 | destructor Destroy; override;
|
---|
15 | end;
|
---|
16 |
|
---|
17 | TDirection = (drNorth, drEasy, drSouth, drWest);
|
---|
18 |
|
---|
19 | TRobotKarel = class
|
---|
20 | Board: array [0..9, 0..9] of Boolean;
|
---|
21 | Position: TPoint;
|
---|
22 | Direction: TDirection;
|
---|
23 | end;
|
---|
24 |
|
---|
25 | TMainForm = class(TForm)
|
---|
26 | RichEdit1: TRichEdit;
|
---|
27 | procedure FormShow(Sender: TObject);
|
---|
28 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
29 | procedure GridPanel1Click(Sender: TObject);
|
---|
30 | private
|
---|
31 | { Private declarations }
|
---|
32 | public
|
---|
33 | VirtualProcessor: TVirtualProcessor;
|
---|
34 | ProgramEdit: TProgramEdit;
|
---|
35 | end;
|
---|
36 |
|
---|
37 | var
|
---|
38 | MainForm: TMainForm;
|
---|
39 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | {$R *.dfm}
|
---|
43 |
|
---|
44 | procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
45 | begin
|
---|
46 | //Memo1.Lines.SaveToFile('Sample.pas');
|
---|
47 | end;
|
---|
48 |
|
---|
49 | procedure TMainForm.FormShow(Sender: TObject);
|
---|
50 | begin
|
---|
51 | //Memo1.Lines.LoadFromFile('Sample.pas');
|
---|
52 | ProgramEdit := TProgramEdit.Create(Self);
|
---|
53 | with ProgramEdit do begin
|
---|
54 | Parent := Self;
|
---|
55 | Width := 500;
|
---|
56 | Height := 500;
|
---|
57 | Top := 100;
|
---|
58 | Left := 100;
|
---|
59 | with Code do begin
|
---|
60 | Add('begin');
|
---|
61 | Add(' WriteLn(''Test'')');
|
---|
62 | Add('end.');
|
---|
63 | end;
|
---|
64 | end;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TMainForm.GridPanel1Click(Sender: TObject);
|
---|
68 | begin
|
---|
69 |
|
---|
70 | end;
|
---|
71 |
|
---|
72 | { TProgramEdit }
|
---|
73 |
|
---|
74 | constructor TProgramEdit.Create(AOwner: TComponent);
|
---|
75 | begin
|
---|
76 | inherited;
|
---|
77 | Code := TStringList.Create;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | destructor TProgramEdit.Destroy;
|
---|
81 | begin
|
---|
82 | Code.Free;
|
---|
83 | inherited;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | procedure TProgramEdit.Paint;
|
---|
87 | var
|
---|
88 | I: Integer;
|
---|
89 | const
|
---|
90 | LeftMargin: Integer = 30;
|
---|
91 | begin
|
---|
92 | with Canvas do begin
|
---|
93 | Brush.Color := clGray;
|
---|
94 | FillRect(Rect(0, 0, LeftMargin, Height));
|
---|
95 | Brush.Color := clWhite;
|
---|
96 | FillRect(Rect(LeftMargin, 0, Width, Height));
|
---|
97 | for I := 0 to Code.Count - 1 do begin
|
---|
98 | Brush.Color := clWhite;
|
---|
99 | Font.Color := clBlack;
|
---|
100 | TextOut(LeftMargin + 2, (Abs(Font.Height) + 2) * I, Code[I]);
|
---|
101 | Brush.Color := clGray;
|
---|
102 | Font.Color := clWhite;
|
---|
103 | TextOut(LeftMargin - 20, (Abs(Font.Height) + 2) * I, IntToStr(I));
|
---|
104 | end;
|
---|
105 | end;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | end.
|
---|