Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Interaction with UI    [ Add a report in this area ]  
Report #:  78614   Status: Open
Inserting const/var setions into a TForm causes parser to mafunction on later ading comtrols via visual IDE
Project:  Delphi Build #:  11.0.2902.10471
Version:    11.2 Submitted By:   Stephen Ransom
Report Type:  Minor failure / Design problem Date Reported:  10/13/2009 5:45:35 PM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   273304
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
I have form-specific constants.

I don't like globals of any sort so I didn't want to use a unit-level const section.

I therefore added a "const" section to a TForm in the simplest way possible - immediately under the line defining the new TForm where it was nearly as easy to see as a unit-level const section..

This required adding a "var" line after the const entries.

This works fine.

However .. when then adding a new control to the form via the visual IDE (using the mouse) Delphi places the entry for the new control into the const section, not the var section - and hence the subsequent compile fails.

type
  TfrmiAssort = class(TForm)
  const
    ORA_SOURCE_MANIFEST  = 'manifest';
    ORA_SOURCE_WAVEFRONT = 'wavefront';
    ORA_SOURCE_NA        = '';
    SpeedButton1: TSpeedButton;
  var
    actHintsOnOff                                 : TAction;
    actLoad                                       : TAction;
    actLoad1                                      : TMenuItem;
    actLoadFrom                                   : TAction;
    actManifestORA                                : TAction;
    actSave                                       : TAction;

Workaround .. move the const/var to Private. Not as good since the const is now harder to see.  
Steps to Reproduce:
Create a new form.
Add a TButton.
Compile .. works.
Add
    const
       FRED='Fred';
immediately after the TForm definition line.
Add a second TButton.
Compile - fails E2029 '=' expected but ';' found



unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
  const
    FRED ='Fred';
    Button2: TButton;
  var
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.
  
Workarounds
Move to the Private section.

Not as practical since the constants are now effectively hidden rather than up-front.

(used the mouse to add a third TButton) ...
Compile works.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
  private
  const
    FRED ='Fred';
  var
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

end.
Attachment
None
Comments

None

Server Response from: ETNACODE01