New versions of Pascal Analyzer and Pascal Expert

We are busy preparing our products for the just released Delphi 10.3 Rio. Even so, we have had time to create updates of Pascal Analyzer and Pascal Expert. There are new versions of both products. Current version is 9.3.

In this version, in addition to the usual minor bug fixes and small improvements, there are two new report sections. We will describe them in the following.


STWA10 (Strong Warnings Report, section 10) - Out parameter read before set

A parameter passed as "out" is really just a placeholder, and is supposed to be set by the called function or procedure. Actually it is zero-initialized when the function/procedure starts. Consider this scenario:

procedure Proc(out Delta: Integer);
begin
  ..

  if Delta > 10 then 
  begin
  ..
  end;
  ..
  Delta := SomeValue;
  ..
end;

Here, Delta is read before it is set, and this will trigger a warning. Read more about this topic in our blog article.


WARN62 (Warnings Report, section 62) - Possible orphan event handler

This new report section lists methods in a form class that are (probably) event handlers, but that are not coupled to any control. They may have been coupled at some point, but the link has got lost. Consider for example a button with the OnClick property set to the method, but which has later been removed. Probably this is a mistake by the developer and should be fixed. Sometimes the event handler is assigned in code instead, which is totally fine.

Consider this somewhat artifical example:

This form has two buttons. The code for the form is this:

unit WARN62Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm8 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form8: TForm8;

implementation

{$R *.dfm}

procedure TForm8.Button1Click(Sender: TObject);
begin
  //
  // some code here..
  //
end;

procedure TForm8.Button2Click(Sender: TObject);
begin
  //
  // some code here..
  //
end;

end.

The DFM file contains this:

object Form8: TForm8
  Left = 0
  Top = 0
  Caption = 'Form8'
  ClientHeight = 299
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 104
    Top = 144
    Width = 153
    Height = 65
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 288
    Top = 144
    Width = 153
    Height = 65
    Caption = 'Button2'
    TabOrder = 1
  end
end

As you can see from the DFM, Button1 has its OnClick property coupled to the method Button1Click. But Button2 has not got any property value for OnClick. This means that the Button2Click method is an orphan. It will never get called. Either it should be recoupled to Button2 or removed.

When running Pascal Analyzer or Pascal Expert, a warning will be given:

In this particular situation, with a missing OnClick event, the report section COWA6-"Buttons/menu items with OnClick-event that is unassigned" in the Control Warnings Report, also gives a warning.