BCS Data Entry Panel Code Generator


There are those time when users would like to use data entry dialogs as opposed to the spreadsheet or grid approach of data entry. Memo data entry is normally handed in a separate tab on the tabbed panel.
BCSDE01
I have automated the process of generating data entry panels by traversing the MySQL database and extracting metadata. The metadata is then used to create data entry code which are available in a scroll box in case more datum than will fit in the default form size exists.  This application was written in Delphi XE3.
I then select the .dfm of the targeted application’s form and the data source and table name are detected and extracted.
The extracted table name is then opened and all the fields in the table are used as input to generate the data entry panel codes. The results are then stored in the forms directory as FormName_dfm.txt for the code that needs to be in the form designer and FormName_pas.txt for the data definitions for the form that reside in the Pascal code portion of the form.
Create a new tab on the form and add a scroll box aligned to the client. Open the two files (FormName_dfm.txt and FormName_pas.txt) in the Delphi IDE.
Copy the contents of the _pas file to the clipboard. Position in the form’s class so the data definitions are inserted before any properties, function and methods section of the form and paste from clipboard.
[codesyntax lang=”delphi”]

    DBEdit01: TDBEdit;
    DBEdit02: TDBEdit;
    DBEdit03: TDBEdit;
    DBEdit04: TDBEdit;
    DBEdit05: TDBEdit;
    DBEdit06: TDBEdit;
    DBEdit07: TDBEdit;
    DBEdit08: TDBEdit;
    DBEdit09: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit11: TDBEdit;
    DBEdit12: TDBEdit;
    DBEdit13: TDBEdit;
    DBMemo14: TDBMemo;
    Label01: TLabel;
    Label02: TLabel;
    Label03: TLabel;
    Label04: TLabel;
    Label05: TLabel;
    Label06: TLabel;
    Label07: TLabel;
    Label08: TLabel;
    Label09: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;

[/codesyntax]
Now copy the contents of the _dfm to the clipboard. Navigate to the designer and view for as text. Move to the “end” statement of the scroll box. Paste the contents of the clipboard at that location.
[codesyntax lang=”delphi”]

        object DBEdit01: TDBEdit
          Left = 135
          Top = 0
          Width = 241
          Height = 21
          DataField = 'cid'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 01
        end
        object DBEdit02: TDBEdit
          Left = 135
          Top = 26
          Width = 241
          Height = 21
          DataField = 'name'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 02
        end
        object DBEdit03: TDBEdit
          Left = 135
          Top = 52
          Width = 241
          Height = 21
          DataField = 'adr1'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 03
        end
        object DBEdit04: TDBEdit
          Left = 135
          Top = 78
          Width = 241
          Height = 21
          DataField = 'adr2'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 04
        end
        object DBEdit05: TDBEdit
          Left = 135
          Top = 104
          Width = 241
          Height = 21
          DataField = 'city'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 05
        end
        object DBEdit06: TDBEdit
          Left = 135
          Top = 130
          Width = 241
          Height = 21
          DataField = 'state'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 06
        end
        object DBEdit07: TDBEdit
          Left = 135
          Top = 156
          Width = 241
          Height = 21
          DataField = 'zip'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 07
        end
        object DBEdit08: TDBEdit
          Left = 135
          Top = 182
          Width = 241
          Height = 21
          DataField = 'poc'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 08
        end
        object DBEdit09: TDBEdit
          Left = 135
          Top = 208
          Width = 241
          Height = 21
          DataField = 'phone'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 09
        end
        object DBEdit10: TDBEdit
          Left = 135
          Top = 234
          Width = 241
          Height = 21
          DataField = 'email'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 10
        end
        object DBEdit11: TDBEdit
          Left = 135
          Top = 260
          Width = 241
          Height = 21
          DataField = 'web'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 11
        end
        object DBEdit12: TDBEdit
          Left = 135
          Top = 286
          Width = 241
          Height = 21
          DataField = 'uid'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 12
        end
        object DBEdit13: TDBEdit
          Left = 135
          Top = 312
          Width = 241
          Height = 21
          DataField = 'pwd'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 13
        end
        object DBMemo14: TDBMemo
          Left = 135
          Top = 338
          Width = 241
          Height = 89
          DataField = 'addr'
          DataSource = BCSCompdm.adsei_comp
          ParentColor = True
          TabOrder = 14
        end
        object BitBtn1: TBitBtn
          Left = 152
          Top = 528
          Width = 75
          Height = 25
          Kind = bkOK
          NumGlyphs = 2
          TabOrder = 17
        end
        object BitBtn2: TBitBtn
          Left = 256
          Top = 528
          Width = 75
          Height = 25
          Kind = bkCancel
          NumGlyphs = 2
          TabOrder = 18
        end
        object Label01: TLabel
          Left = 22
          Top = 0
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'cid :  '
        end
        object Label02: TLabel
          Left = 22
          Top = 26
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'name :  '
        end
        object Label03: TLabel
          Left = 22
          Top = 52
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'adr1 :  '
        end
        object Label04: TLabel
          Left = 22
          Top = 78
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'adr2 :  '
        end
        object Label05: TLabel
          Left = 22
          Top = 104
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'city :  '
        end
        object Label06: TLabel
          Left = 22
          Top = 130
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'state :  '
        end
        object Label07: TLabel
          Left = 22
          Top = 156
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'zip :  '
        end
        object Label08: TLabel
          Left = 22
          Top = 182
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'poc :  '
        end
        object Label09: TLabel
          Left = 22
          Top = 208
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'phone :  '
        end
        object Label10: TLabel
          Left = 22
          Top = 234
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'email :  '
        end
        object Label11: TLabel
          Left = 22
          Top = 260
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'web :  '
        end
        object Label12: TLabel
          Left = 22
          Top = 286
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'uid :  '
        end
        object Label13: TLabel
          Left = 22
          Top = 312
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'pwd :  '
        end
        object Label14: TLabel
          Left = 22
          Top = 338
          Width = 107
          Height = 13
          Alignment = taRightJustify
          AutoSize = False
          Caption = 'addr :  '
        end

[/codesyntax]
View the form as a form and you will see the scroll box populated with data elements.
[codesyntax lang=”delphi”]

{*-----------------------------------------------------------------------------
 Unit Name: BCSCompU
 @Author Mr. Arch Brooks, Software Engineer, Brooks Computing Systems LLC
 @Version 1.0
 Date:      04-Jan-2014
 Purpose:
 History:
 -----------------------------------------------------------------------------}
unit BCSCompU;
interface
uses
  BCSXE3Utilsdp, System.Classes, System.SysUtils, System.Variants,
  BCSCompdmU, Vcl.ComCtrls, Vcl.Controls, Vcl.DBCtrls, Vcl.Dialogs,
  Vcl.ExtCtrls, Vcl.Forms, Vcl.Graphics, Vcl.Grids, Vcl.Menus, Vcl.StdCtrls,
  Vcl.TabNotBk, Winapi.Messages, Winapi.Windows, Vcl.DBGrids, Vcl.Buttons,
  Vcl.Mask;
type
  /// DB Grid Class Overide
  TDBGrid = class(Vcl.DBGrids.TDBGrid)
  protected
    procedure Paint; override;
  end;
  /// Tab Sheet Class
  TTabSheet = class(Vcl.ComCtrls.TTabSheet)
  private
    /// Tab Control Color
    FColor: TColor;
    procedure SetColor(Value: TColor);
    procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
  public
    constructor Create(aOwner: TComponent); override;
    property Color: TColor read FColor write SetColor;
  end;
  /// BCSComp Primary Class
  TBCSCompC = class(TForm)
    /// BCS XE3 Utilities Component
    BCSXE3UtilsCmp1: TBCSXE3UtilsCmp;
    /// BCSComp Color Dialog
    BCSCompColor: TColorDialog;
    /// BCSComp Colors Menu Item
    BCSCompColors1: TMenuItem;
    /// BCSComp DB Navigator
    BCSCompDBNavigator1: TDBNavigator;
    /// BCSComp DB Memo
    BCSCompDBMemo1: TDBMemo;
    /// BCSComp SB Grid
    BCSCompDBGrid1: TDBGrid;
    /// BCSPageColor Main Menu
    BCSCompMainMenu1: TMainMenu;
    /// Main Page Control
    BCSCompPageControl1: TPageControl;
    /// Help Menu Item
    BCSCompHelp1: TMenuItem;
    /// Status Panel For Dialog
    BCSCompStatusPanel1: TStatusBar;
    /// Tab sheet 1 for page control
    BCSCompTabSheet1: TTabSheet;
    /// Tab sheet 2 for page control
    BCSCompTabSheet2: TTabSheet;
    /// Timer for Dialog
    BCSCompTimer1: TTimer;
    tasDataEntryForm: TTabSheet;
    ScrollBox1: TScrollBox;
    DBEdit01: TDBEdit;
    DBEdit02: TDBEdit;
    DBEdit03: TDBEdit;
    DBEdit04: TDBEdit;
    DBEdit05: TDBEdit;
    DBEdit06: TDBEdit;
    DBEdit07: TDBEdit;
    DBEdit08: TDBEdit;
    DBEdit09: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit11: TDBEdit;
    DBEdit12: TDBEdit;
    DBEdit13: TDBEdit;
    DBMemo14: TDBMemo;
    Label01: TLabel;
    Label02: TLabel;
    Label03: TLabel;
    label04: TLabel;
    Label05: TLabel;
    Label06: TLabel;
    Label07: TLabel;
    Label08: TLabel;
    Label09: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Panel1: TPanel;
    Panel2: TPanel;
    procedure BCSCompColors1Click(Sender: TObject);
    procedure BCSCompCreate(Sender: TObject);
    procedure BCSCompDBGrid1TitleClick(Column: TColumn);
    procedure BCSCompDrawTab(Control: TCustomTabControl; TabIndex: Integer;
      const Rect: TRect; Active: Boolean);
    procedure BCSCompFormActivate(Sender: TObject);
    procedure BCSCompGridColor;
    procedure BCSCompHelp1Click(Sender: TObject);
    procedure BCSCompStatusBar1DrawPanel(StatusBar: TStatusBar;
      Panel: TStatusPanel; const Rect: TRect);
    procedure BCSCompTimer1Timer(Sender: TObject);
  private
    {Private declarations}
    FDColor: TColor;
  public
    {Public declarations}
    property RDColor: TColor read FDColor write FDColor;
  end;
var
  /// BCSComp Dialog Pointer
  BCSCompC: TBCSCompC;
implementation
{$R *.dfm}
var
  /// TimeStamp Variable
  ftime: String;
  /// Item Index
  i: Integer;
{*-----------------------------------------------------------------------------
  Procedure: Paint
  Date:      06-Jan-2014
  @Param     None
  @Return    None
-----------------------------------------------------------------------------}
procedure TDBGrid.Paint;
var
  LDrawInfo: TGridDrawInfo;
begin
  inherited Paint;
  CalcDrawInfo(LDrawInfo);
  if LDrawInfo.Horz.GridBoundary < LDrawInfo.Horz.GridExtent then
  begin
    Canvas.Brush.Color := Color;
    // use the Color property to paint the background
    Canvas.FillRect(Rect(LDrawInfo.Horz.GridBoundary, 0,
      LDrawInfo.Horz.GridExtent, LDrawInfo.Vert.GridBoundary));
  end;
  if LDrawInfo.Vert.GridBoundary < LDrawInfo.Vert.GridExtent then
  begin
    Canvas.Brush.Color := Color;
    // use the Color property to paint the background
    Canvas.FillRect(Rect(0, LDrawInfo.Vert.GridBoundary,
      LDrawInfo.Horz.GridExtent, LDrawInfo.Vert.GridExtent));
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: Create
 Date:      04-Jan-2014
 @Param     aOwner: TComponent
 @Return    None
 -----------------------------------------------------------------------------}
constructor TTabSheet.Create(aOwner: TComponent);
begin
  inherited;
  FColor := clWhite;
end;
{*-----------------------------------------------------------------------------
 Procedure: SetColor
 Date:      04-Jan-2014
 @Param     Value: TColor
 @Return    None
 -----------------------------------------------------------------------------}
procedure TTabSheet.SetColor(Value: TColor);
begin
  if FColor <> Value then
  begin
    FColor := Value;
    Invalidate;
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: WMEraseBkGnd
 Date:      04-Jan-2014
 @Param     var Msg: TWMEraseBkGnd
 @Return    None
 -----------------------------------------------------------------------------}
procedure TTabSheet.WMEraseBkGnd(var Msg: TWMEraseBkGnd);
begin
  if FColor = clBtnFace then
    inherited
  else
  begin
    Brush.Color := FColor;
    FillRect(Msg.dc, ClientRect, Brush.Handle);
    Msg.Result := 1;
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompColors1Click
 Date:      04-Jan-2014
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompColors1Click(Sender: TObject);
var
  ti: Integer;
begin
  if BCSCompColor.Execute then
  begin
    Color := BCSCompColor.Color;
    RDColor := Color;
    BCSCompTabSheet1.Color := Color;
    BCSCompTabSheet2.Color := Color;
    BCSCompDBGrid1.Color := Color;
    BCSCompStatusPanel1.Color := Color;
    BCSCompGridColor;
    BCSCompDBGrid1.Repaint;
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompCreate
 Date:      04-Jan-2014
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompCreate(Sender: TObject);
begin
  Color := RDColor;
  BCSCompTabSheet1.Color := Color;
  BCSCompTabSheet2.Color := Color;
  BCSCompDBGrid1.Color := Color;
  BCSCompStatusPanel1.Color := Color;
  BCSCompGridColor;
  BCSCompDBGrid1.Repaint;
  {BCSCompTabSheet1.Color := Color;
   BCSCompTabSheet2.Color := Color;
   BCSCompStatusPanel1.Color := Color;
   BCSCompGridColor;}
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompDBGrid1TitleClick
 Date:      04-Jan-2014
 @Param     Column: TColumn
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompDBGrid1TitleClick(Column: TColumn);
begin
  BCSCompdm.ataei_comp.IndexFieldNames := Column.FieldName;
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompDrawTab
 Date:      04-Jan-2014
 @Param     Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect;
 Active: Boolean
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompDrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  AText: string;
  APoint: TPoint;
begin
  with (Control as TPageControl).Canvas do
  begin
    Brush.Color := Color;
    FillRect(Rect);
    AText := TPageControl(Control).Pages[TabIndex].Caption;
    with Control.Canvas do
    begin
      APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2;
      APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2;
      TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText);
    end;
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: FormActivate
 Date:      04-Jan-2014
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompFormActivate(Sender: TObject);
begin
  Color := RDColor;
  BCSCompDBGrid1.Invalidate;
  BCSCompDBGrid1.Color := Color;
  BCSCompDBGrid1.Canvas.Brush.Color := Color;
  BCSCompDBGrid1.Canvas.Refresh;
  BCSCompGridColor;
  BCSCompTabSheet1.Color := Color;
  BCSCompTabSheet2.Color := Color;
  BCSCompStatusPanel1.Color := Color;
  BCSCompStatusPanel1.Color := Color;
  i := 0;
  repeat
    if Self.BCSCompDBGrid1.Columns[i].Width > 150 then
    begin
      Self.BCSCompDBGrid1.Columns[i].Width := 150;
    end;
    Inc(i);
  until (i > (Self.BCSCompDBGrid1.Columns.Count - 1));
  BCSCompdm.ataei_comp.Open;
  BCSCompStatusPanel1.Panels[0].Text := 'Record Count is : ' +
    FormatFloat('#,##0', BCSCompdm.ataei_comp.RecordCount);
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompGridColor
 Date:      04-Jan-2014
 @Param     None
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompGridColor;
begin
  // Color := RDColor;
  i := 0;
  repeat
    BCSCompDBGrid1.Columns[i].Color := Color;
    Inc(i);
  until i > BCSCompDBGrid1.Columns.Count - 1;
  // BCSCompDBGrid1.Repaint;
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompHelp1Click
 Date:      04-Jan-2014
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompHelp1Click(Sender: TObject);
begin
  BCSXE3UtilsCmp1.ShellExec('http://bcswebs.us/bcs002/');
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompStatusBar1DrawPanel
 Date:      04-Jan-2014
 @Param     StatusBar: TStatusBar; Panel: TStatusPanel; const Rect: TRect
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompStatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
begin
  with StatusBar.Canvas do
  begin
    FillRect(Rect);
    case Panel.Index of
      0: // fist panel
        begin
          Brush.Color := Color;
          Font.Color := clBlack;
          // Font.Style := [fsBold];
          TextRect(Rect, 2 + Rect.Left, 2 + Rect.Top, Panel.Text);
        end;
      1: // second panel
        begin
          Brush.Color := Color;
          Font.Color := clBlack;
          // Font.Style := [fsItalic];
          TextRect(Rect, 2 + Rect.Left, 2 + Rect.Top, Panel.Text);
        end;
      2: // Third panel
        begin
          Brush.Color := Color;
          Font.Color := clBlack;
          // Font.Style := [fsItalic];
          Panel.Text := ftime;
          TextRect(Rect, 2 + Rect.Left, 2 + Rect.Top, Panel.Text);
          TextOut(0, 0, ftime);
        end;
    end;
  end;
end;
{*-----------------------------------------------------------------------------
 Procedure: BCSCompTimer1Timer
 Date:      04-Jan-2014
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSCompC.BCSCompTimer1Timer(Sender: TObject);
begin
  DateTimeToString(ftime, 'dddd, mmmm dd, yyyy hh:mm:ss     ', now);
  BCSCompStatusPanel1.Panels[2].Text := ftime;
end;
end.

[/codesyntax]
The BCS XE3 code generator provides the basic form functionality with a data module, database navigator, database grid and memo editor. That generated code is input to this tool. Code generators are quite useful and saves countless hours of perfunctory coding tedium.
Depending in user interest I will make the source code available for this tool.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article

Leave a Reply

Your email address will not be published. Required fields are marked *