Ignore:
Timestamp:
Jul 20, 2018, 9:41:37 AM (6 years ago)
Author:
chronos
Message:
  • Added: Allow to enable individual code optimization from settings dialog.
  • Added: Actions to format or shrink target BF code.
Location:
trunk/Forms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms

    • Property svn:ignore set to
      *.lrj
  • trunk/Forms/UFormTargetCode.pas

    r46 r91  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Menus;
     9  Menus, ActnList, strutils;
    1010
    1111type
     
    1414
    1515  TFormTargetCode = class(TForm)
     16    AShrinkCode: TAction;
     17    AFormatCode: TAction;
     18    ActionList1: TActionList;
    1619    MemoTarget: TMemo;
     20    MenuItem1: TMenuItem;
    1721    MenuItem20: TMenuItem;
    1822    PopupMenuTarget: TPopupMenu;
     23    procedure AFormatCodeExecute(Sender: TObject);
     24    procedure AShrinkCodeExecute(Sender: TObject);
    1925  private
    2026    { private declarations }
     
    3036{$R *.lfm}
    3137
     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
    3286end.
    3387
Note: See TracChangeset for help on using the changeset viewer.