source: branches/xpascal/Forms/FormConsole.pas

Last change on this file was 230, checked in by chronos, 17 months 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 
1unit FormConsole;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FormEx;
7
8type
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
27implementation
28
29{$R *.lfm}
30
31{ TFormConsole }
32
33procedure TFormConsole.Memo1KeyPress(Sender: TObject; var Key: char);
34begin
35 if Key = #13 then begin
36 InputStrings.Add(InputBuffer);
37 InputBuffer := '';
38 end else InputBuffer := InputBuffer + Key;
39 Memo1.Text := Memo1.Text + Key;
40end;
41
42procedure TFormConsole.FormCreate(Sender: TObject);
43begin
44 InputStrings := TStringList.Create;
45end;
46
47procedure TFormConsole.FormClose(Sender: TObject; var CloseAction: TCloseAction
48 );
49begin
50 Terminated := True;
51end;
52
53procedure TFormConsole.FormDestroy(Sender: TObject);
54begin
55 Terminated := True;
56 FreeAndNil(InputStrings);
57end;
58
59function TFormConsole.GetInputString: string;
60begin
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;
73end;
74
75end.
76
Note: See TracBrowser for help on using the repository browser.