|
Last change
on this file was 230, checked in by chronos, 2 years ago |
- Added: Var function parameters support.
- Added: Read and ReadLn procedures support.
- Added: Interpreter now prints into console form.
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | unit FormConsole;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FormEx;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | { TFormConsole }
|
|---|
| 11 |
|
|---|
| 12 | TFormConsole = class(TFormEx)
|
|---|
| 13 | Memo1: TMemo;
|
|---|
| 14 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
|---|
| 15 | procedure FormCreate(Sender: TObject);
|
|---|
| 16 | procedure FormDestroy(Sender: TObject);
|
|---|
| 17 | procedure Memo1KeyPress(Sender: TObject; var Key: char);
|
|---|
| 18 | private
|
|---|
| 19 | InputBuffer: string;
|
|---|
| 20 | InputStrings: TStringList;
|
|---|
| 21 | public
|
|---|
| 22 | Terminated: Boolean;
|
|---|
| 23 | function GetInputString: string;
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | implementation
|
|---|
| 28 |
|
|---|
| 29 | {$R *.lfm}
|
|---|
| 30 |
|
|---|
| 31 | { TFormConsole }
|
|---|
| 32 |
|
|---|
| 33 | procedure TFormConsole.Memo1KeyPress(Sender: TObject; var Key: char);
|
|---|
| 34 | begin
|
|---|
| 35 | if Key = #13 then begin
|
|---|
| 36 | InputStrings.Add(InputBuffer);
|
|---|
| 37 | InputBuffer := '';
|
|---|
| 38 | end else InputBuffer := InputBuffer + Key;
|
|---|
| 39 | Memo1.Text := Memo1.Text + Key;
|
|---|
| 40 | end;
|
|---|
| 41 |
|
|---|
| 42 | procedure TFormConsole.FormCreate(Sender: TObject);
|
|---|
| 43 | begin
|
|---|
| 44 | InputStrings := TStringList.Create;
|
|---|
| 45 | end;
|
|---|
| 46 |
|
|---|
| 47 | procedure TFormConsole.FormClose(Sender: TObject; var CloseAction: TCloseAction
|
|---|
| 48 | );
|
|---|
| 49 | begin
|
|---|
| 50 | Terminated := True;
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | procedure TFormConsole.FormDestroy(Sender: TObject);
|
|---|
| 54 | begin
|
|---|
| 55 | Terminated := True;
|
|---|
| 56 | FreeAndNil(InputStrings);
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | function TFormConsole.GetInputString: string;
|
|---|
| 60 | begin
|
|---|
| 61 | Result := '';
|
|---|
| 62 | while InputStrings.Count = 0 do begin
|
|---|
| 63 | Application.ProcessMessages;
|
|---|
| 64 | Sleep(10);
|
|---|
| 65 | if Terminated then begin
|
|---|
| 66 | Exit;
|
|---|
| 67 | end;
|
|---|
| 68 | end;
|
|---|
| 69 | if InputStrings.Count > 0 then begin
|
|---|
| 70 | Result := InputStrings[0];
|
|---|
| 71 | InputStrings.Delete(0);
|
|---|
| 72 | end;
|
|---|
| 73 | end;
|
|---|
| 74 |
|
|---|
| 75 | end.
|
|---|
| 76 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.