-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnit1.pas
More file actions
125 lines (105 loc) · 3.38 KB
/
Unit1.pas
File metadata and controls
125 lines (105 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, SynEdit,
SynEditHighlighter, SynEditCodeFolding, SynHighlighterPas, Vcl.Buttons,
System.Skia, Vcl.Skia;
type
TForm1 = class(TForm)
SynEdit1: TSynEdit;
Panel1: TPanel;
LazyEvaluateButton: TButton;
ListBox1: TListBox;
RadioGroup1: TRadioGroup;
UsedInAFunctionButton: TButton;
HowManyLightsButton: TButton;
SynPasSyn1: TSynPasSyn;
Label1: TLabel;
Panel2: TPanel;
SkSvg1: TSkSvg;
GridPanel1: TGridPanel;
procedure LazyEvaluateButtonClick(Sender: TObject);
procedure HowManyLightsButtonClick(Sender: TObject);
procedure UsedInAFunctionButtonClick(Sender: TObject);
procedure SkSvg1Click(Sender: TObject);
private
procedure MyFunction(ALeft, AArg1: integer; const AText1, AText2: string);
function SomeOtherTest: boolean;
procedure LoadSyn(const AText: string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses modules.strings, System.IOUtils, SynEditTypes;
procedure TForm1.MyFunction(ALeft, AArg1: integer; const AText1, AText2: string);
begin
ShowMessage('ALeft=' + ALeft.ToString
+ ', AArg1=' + AArg1.ToString
+ ', AText1=' + AText1
+ ', AText2=' + AText2);
end;
procedure TForm1.UsedInAFunctionButtonClick(Sender: TObject);
begin
LoadSyn('procedure TForm1.UsedInAFunctionButtonClick');
Myfunction(Left,
if Screen.Width < 2000 then 100 else Screen.Width div 200,
if SomeOtherTest then 'Small' else 'Not small',
'Big');
end;
procedure TForm1.SkSvg1Click(Sender: TObject);
begin
SynEdit1.SelectAll;
SynEdit1.CopyToClipboard;
SynEdit1.SelStart := -1;
SynEdit1.SelEnd := -1;
ShowMessage('Code copied to clipboard');
end;
function TForm1.SomeOtherTest: boolean;
begin
Result := Random(1) = 0;
end;
procedure TForm1.HowManyLightsButtonClick(Sender: TObject);
begin
LoadSyn('procedure TForm1.HowManyLightsButtonClick');
Listbox1.Items.Clear;
for var Lights := 0 to 4 do
ListBox1.Items.Add(' I see ' + Lights.ToString + ' light' + if Lights = 1 then '' else 's');
end;
procedure TForm1.LazyEvaluateButtonClick(Sender: TObject);
var
LString: string;
function Dog: string;
begin
ListBox1.Items.Add(' Dog evaluated');
Result := 'dog';
end;
function Cat: string;
begin
ListBox1.Items.Add(' Cat evaluated');
Result := 'cat';
end;
begin
LoadSyn('procedure TForm1.LazyEvaluateButtonClick');
Listbox1.Items.Clear;
LString := if RadioGroup1.ItemIndex = 0 then Dog else Cat;
Listbox1.Items.Add(' "' + LString + '" is the result');
end;
procedure TForm1.LoadSyn(const AText: string);
begin
// It would be WAY better to replace AText with the procedure name via RTTI but that puts too much of a burden on this little app
SynEdit1.Lines.Clear;
var sCode := TPath.Combine(ExtractFilePath(Application.ExeName), Self.UnitName + '.pas');
if not FileExists(sCode) then
ShowMessage('The source code "' + sCode + '" can''t be found.' + sLineBreak
+ 'Try setting the exe to be created in the same folder as the .pas files')
else
begin
SynEdit1.Text := GetCode(sCode, AText);
SynEdit1.TopLine := 0;
SynEdit1.Options := SynEdit1.Options - [eoNoCaret];
SkSvg1.Visible := True;
end;
end;
end.