Formatted Version of ObjectPascal Code

This page contains some Badly Formatted ObjectPascal code, and its ObjectPascal Formatted version. The output was produced by our ObjectPascal Formatter.

Badly Formatted ObjectPascal Code

This code is part of a student Computer Science Jeopardy game manager. The author's orginal version (used with his permission) was nicely formatted; we have purposely ruined the formatting to simulate what a really bad programmer might do to the formatting without breaking the code. Most programmers will have to reformat this to have any chance of understanding it. There goes half an hour of productivity.


unit unitRound2; interface uses
  Windows, Messages
,
				SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  ExtCtrls
, Menus					  , StdCtrls, JeopardyButton, Db, DBTables;

type  TfrmRound2 = class(TForm)    Panel1: TPanel;    Splitter1: TSplitter;    Panel2: TPanel;
    Splitter2: TSplitter;    Panel3: TPanel;
        Splitter3: TSplitter;
     Panel4: TPanel;
       Panel5: TPanel;
        PopupMenu1: TPopupMenu;
          EditTeamData1: TMenuItem;
            lblTeam1: TLabel;
                lblTeam2: TLabel;
                                                               lblTeam3: TLabel;    lblCat1: TLabel;
                                                 lblCat2: TLabel; lblCat3:
 TLabel;  lblCat4:
					 TLabel;  btnR1C1
		:
 TJeopardyButton;
btnr2c1:TJeopardyButton;btnr3c1:TJeopardyButton;btnr4c1:TJeopardyButton;btnr5c1:TJeopardyButton;
JeopardyButton1:TJeopardyButton;JeopardyButton2:TJeopardyButton;JeopardyButton3:TJeopardyButton;
JeopardyButton4:TJeopardyButton;JeopardyButton5:TJeopardyButton;JeopardyButton6:TJeopardyButton;
    JeopardyButton7: TJeopardyButton;    JeopardyButton8: TJeopardyButton;
JeopardyButton9
: TJeopardyButton;  JeopardyButton10
 : TJeopardyButton;  JeopardyButton11
   : TJeopardyButton; JeopardyButton12
     : TJeopardyButton;
 JeopardyButton13: TJeopardyButton;
    JeopardyButton14: TJeopardyButton;
     JeopardyButton15: TJeopardyButton;
     qryButtonQuestion: TQuery;
       qryButtonQuestionQuestion: TMemoField;
          qryButtonQuestionAnswer: TMemoField;
      qryButtonQuestionQuestionString: TStringField;
      qryButtonQuestionAnswerString: TStringField;
     qryButtonQuestionIncludePic: TStringField;
                                             qryButtonQuestionPicFile: TStringField;
                                                                             Label2: TLabel;
                           PopupMenu2: TPopupMenu;  GotoFinalJeopardy1: TMenuItem;    lblTeam4: TLabel;
procedure FormCreate
(Sender
: TObject);  procedure EditTeamData1Click(Sender
: TObject
);  procedure FormShow(Sender: TObject);  procedure btnR1C1Click(Sender: TObject);  procedure qryButtonQuestionQuestionGetText(Sender: TField;  var
 Text
:						 String; DisplayText: Boolean);
  procedure qryButtonQuestionAnswerGetText(
Sender: TField; var Text:
 String; DisplayText:
 Boolean);
    procedure GotoFinalJeopardy1Click(Sender: TObject);  private
    { Private declarations }
  public   procedure DisplayScore;
    { Public declarations }
					  end;

								var
  frmRound2
: TfrmRound2;  implementation
uses unitTeamAdmin
	,				 unitQuestion	, unitFinal;

{$R *.DFM}

procedure
 TfrmRound2
.DisplayScore; begin lblTeam1.Caption
 := Team1.Name + ': ' + IntToStr(Team1.Score); lblTeam2.Caption := Team2.
Name + ': ' + IntToStr(
Team2.Score); lblTeam3.Caption := Team3.Name + ': ' + IntToStr
(Team3.Score); lblTeam4.Caption := Team4.Name + ': '
+ IntToStr(Team4.Score); end;

procedure TfrmRound2.FormCreate(Sender: TObject); var PanelWidth : Integer; begin
Top:=0;Left:=0;

// Set up the panel widths
  PanelWidth := Screen.Width div 4;Panel1.Width := PanelWidth;Panel2.Width := PanelWidth;
  Panel3.Width := PanelWidth;Panel4.Width := PanelWidth
;end


; procedure TfrmRound2.EditTeamData1Click(
Sender: TObject);begin  frmTeamAdmin.ShowModal;  DisplayScore;end; procedure


 TfrmRound2.FormShow(Sender: TObject);begin  CurrentRound :=
 2;   DisplayScore
          ; frmQuestion.MediaPlayer1
.FileName := 'C:\misc\CSJeopardy\Sounds\Round2.wav'; frmQuestion.MediaPlayer1
.Open;  frmQuestion.MediaPlayer1.Play;
			end;

procedure TfrmRound2.btnR1C1Click(Sender: TObject);
begin

 CurrentQuestionValue := StrToInt(TJeopardyButton(Sender).Caption);
			   TJeopardyButton(Sender).Visible := False;

  qryButtonQuestion.Close				      ;
				  qryButtonQuestion.ParamByName('RowParam').AsInteger :=
     TJeopardyButton(Sender).Row;  qryButtonQuestion.ParamByName('ColParam').AsInteger :=
     TJeopardyButton(Sender).Col;   qryButtonQuestion.Open;  frmQuestion.Show;

  with frmQuestion.
RichEdit1 do  begin    Lines






.Clear;   ParaGraph.Alignment := taLeftJustify;    SelAttributes.Size := 32;     SelAttributes.Color := clRed;
      Lines.Add('Question:');   Lines.Add(
' ');      Paragraph.Alignment := taCenter;    SelAttributes.Size := 28;
    SelAttributes.Color := clBlack;     Lines.Add(qryButtonQuestionQuestion.Text);   end;
end; procedure TfrmRound2.qryButtonQuestionQuestionGetText
(Sender: TField;  var Text: String; DisplayText: Boolean); begin  Text :=
 qryButtonQuestionQuestion.AsString; end;procedure TfrmRound2.qryButtonQuestionAnswerGetText(Sender: TField;  var Text: String; DisplayText: Boolean);begin  Text := qryButtonQuestionAnswer.AsString;end;








procedure TfrmRound2.GotoFinalJeopardy1Click(Sender: TObject);
	  begin
			  Close;
						  frmFinal.Show;
							end;

end.

ObjectPascal Formatted Version

This is the result of using SD's ObjectPascalFormatter tool on the sample badly formatted ObjectPascal, using just the default settings. You can see that the formatter has chosen very different line breaks, based on the language structure. The block structure is now clearly visible. A programmer might actually be able to work on this version.


unit unitRound2;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Menus, StdCtrls, JeopardyButton, Db, DBTables;
  type

      TfrmRound2 =
        class (TForm)
          Panel1: TPanel;
          Splitter1: TSplitter;
          Panel2: TPanel;
          Splitter2: TSplitter;
          Panel3: TPanel;
          Splitter3: TSplitter;
          Panel4: TPanel;
          Panel5: TPanel;
          PopupMenu1: TPopupMenu;
          EditTeamData1: TMenuItem;
          lblTeam1: TLabel;
          lblTeam2: TLabel;
          lblTeam3: TLabel;
          lblCat1: TLabel;
          lblCat2: TLabel;
          lblCat3: TLabel;
          lblCat4: TLabel;
          btnR1C1: TJeopardyButton;
          btnr2c1: TJeopardyButton;
          btnr3c1: TJeopardyButton;
          btnr4c1: TJeopardyButton;
          btnr5c1: TJeopardyButton;
          JeopardyButton1: TJeopardyButton;
          JeopardyButton2: TJeopardyButton;
          JeopardyButton3: TJeopardyButton;
          JeopardyButton4: TJeopardyButton;
          JeopardyButton5: TJeopardyButton;
          JeopardyButton6: TJeopardyButton;
          JeopardyButton7: TJeopardyButton;
          JeopardyButton8: TJeopardyButton;
          JeopardyButton9: TJeopardyButton;
          JeopardyButton10: TJeopardyButton;
          JeopardyButton11: TJeopardyButton;
          JeopardyButton12: TJeopardyButton;
          JeopardyButton13: TJeopardyButton;
          JeopardyButton14: TJeopardyButton;
          JeopardyButton15: TJeopardyButton;
          qryButtonQuestion: TQuery;
          qryButtonQuestionQuestion: TMemoField;
          qryButtonQuestionAnswer: TMemoField;
          qryButtonQuestionQuestionString: TStringField;
          qryButtonQuestionAnswerString: TStringField;
          qryButtonQuestionIncludePic: TStringField;
          qryButtonQuestionPicFile: TStringField;
          Label2: TLabel;
          PopupMenu2: TPopupMenu;
          GotoFinalJeopardy1: TMenuItem;
          lblTeam4: TLabel;
          procedure FormCreate(Sender: TObject);
          procedure EditTeamData1Click(Sender: TObject);
          procedure FormShow(Sender: TObject);
          procedure btnR1C1Click(Sender: TObject);
          procedure qryButtonQuestionQuestionGetText(Sender: TField; var Text: string; DisplayText: boolean);
          procedure qryButtonQuestionAnswerGetText(Sender: TField; var Text: string; DisplayText: boolean);
          procedure GotoFinalJeopardy1Click(Sender: TObject);
          private
          { Private declarations }
          public
            procedure DisplayScore;
        { Public declarations }
        end;
  var frmRound2: TfrmRound2;

implementation uses unitTeamAdmin, unitQuestion, unitFinal;

  {$R *.DFM}
  procedure TfrmRound2.DisplayScore;
    begin
      lblTeam1.Caption := Team1. name + ': ' + IntToStr(Team1.Score);
      lblTeam2.Caption := Team2. name + ': ' + IntToStr(Team2.Score);
      lblTeam3.Caption := Team3. name + ': ' + IntToStr(Team3.Score);
      lblTeam4.Caption := Team4. name + ': ' + IntToStr(Team4.Score);
    end;

  procedure TfrmRound2.FormCreate(Sender: TObject);
    var PanelWidth: Integer;
    begin
      Top := 0;
      Left := 0;
      // Set up the panel widths
      PanelWidth := Screen.Width div 4;
      Panel1.Width := PanelWidth;
      Panel2.Width := PanelWidth;
      Panel3.Width := PanelWidth;
      Panel4.Width := PanelWidth;
    end;

  procedure TfrmRound2.EditTeamData1Click(Sender: TObject);
    begin
      frmTeamAdmin.ShowModal;
      DisplayScore;
    end;

  procedure TfrmRound2.FormShow(Sender: TObject);
    begin
      CurrentRound := 2;
      DisplayScore;
      frmQuestion.MediaPlayer1.FileName := 'C:\misc\CSJeopardy\Sounds\Round2.wav';
      frmQuestion.MediaPlayer1.Open;
      frmQuestion.MediaPlayer1.Play;
    end;

  procedure TfrmRound2.btnR1C1Click(Sender: TObject);
    begin
      CurrentQuestionValue := StrToInt(TJeopardyButton(Sender).Caption);
      TJeopardyButton(Sender).Visible := False;
      qryButtonQuestion.Close;
      qryButtonQuestion.ParamByName('RowParam').AsInteger := TJeopardyButton(Sender).Row;
      qryButtonQuestion.ParamByName('ColParam').AsInteger := TJeopardyButton(Sender).Col;
      qryButtonQuestion.Open;
      frmQuestion.Show;
      with frmQuestion.RichEdit1 do
        begin
          Lines.Clear;
          ParaGraph.Alignment := taLeftJustify;
          SelAttributes.Size := 32;
          SelAttributes.Color := clRed;
          Lines.Add('Question:');
          Lines.Add(' ');
          Paragraph.Alignment := taCenter;
          SelAttributes.Size := 28;
          SelAttributes.Color := clBlack;
          Lines.Add(qryButtonQuestionQuestion.Text);
        end;
    end;

  procedure TfrmRound2.qryButtonQuestionQuestionGetText(Sender: TField; var Text: string; DisplayText: boolean);
    begin
      Text := qryButtonQuestionQuestion.AsString;
    end;

  procedure TfrmRound2.qryButtonQuestionAnswerGetText(Sender: TField; var Text: string; DisplayText: boolean);
    begin
      Text := qryButtonQuestionAnswer.AsString;
    end;

  procedure TfrmRound2.GotoFinalJeopardy1Click(Sender: TObject);
    begin
      Close;
      frmFinal.Show;
    end;
end.



ObjectPascal
Formatter Example