source: tags/1.0.0/Forms/UFormTargetCode.pas

Last change on this file was 91, checked in by chronos, 6 years ago
  • Added: Allow to enable individual code optimization from settings dialog.
  • Added: Actions to format or shrink target BF code.
File size: 1.9 KB
Line 
1unit UFormTargetCode;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 Menus, ActnList, strutils;
10
11type
12
13 { TFormTargetCode }
14
15 TFormTargetCode = class(TForm)
16 AShrinkCode: TAction;
17 AFormatCode: TAction;
18 ActionList1: TActionList;
19 MemoTarget: TMemo;
20 MenuItem1: TMenuItem;
21 MenuItem20: TMenuItem;
22 PopupMenuTarget: TPopupMenu;
23 procedure AFormatCodeExecute(Sender: TObject);
24 procedure AShrinkCodeExecute(Sender: TObject);
25 private
26 { private declarations }
27 public
28 { public declarations }
29 end;
30
31var
32 FormTargetCode: TFormTargetCode;
33
34implementation
35
36{$R *.lfm}
37
38{ TFormTargetCode }
39
40procedure TFormTargetCode.AFormatCodeExecute(Sender: TObject);
41var
42 Source: string;
43 NewSource: string;
44 Indent: Integer;
45 I: Integer;
46const
47 IndentText = ' ';
48begin
49 Source := MemoTarget.Text;
50 NewSource := '';
51 Indent := 0;
52 for I := 1 to Length(Source) do begin
53 if Source[I] = '[' then begin
54 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding ;
55 Inc(Indent);
56 NewSource := NewSource + DupeString(IndentText, Indent);
57 end
58 else if Source[I] = ']' then begin
59 Dec(Indent);
60 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding + DupeString(IndentText, Indent);
61 end
62 else if Ord(Source[I]) > $20 then
63 NewSource := NewSource + Source[I];
64 end;
65 MemoTarget.Text := NewSource;
66end;
67
68procedure TFormTargetCode.AShrinkCodeExecute(Sender: TObject);
69var
70 Source: string;
71 Pos: Integer;
72 I: Integer;
73begin
74 Source := MemoTarget.Text;
75 Pos := 1;
76 for I := 1 to Length(Source) do begin
77 if Source[I] > ' ' then begin
78 Source[Pos] := Source[I];
79 Inc(Pos);
80 end;
81 end;
82 SetLength(Source, Pos - 1);
83 MemoTarget.Text := Source;
84end;
85
86end.
87
Note: See TracBrowser for help on using the repository browser.