views:

1445

answers:

6

Delphi 2009 complains with an E2283 error: [DCC Error] outputcode.pas(466): E2283 Too many local constants. Use shorter procedures

Delphi 2007 compiles just fine. I can't find an abundance of local constants, it's a short (500 line) unit. Do you see any abundance of constants or literals I can address?

procedure TOutputCodeForm.FormCreate(Sender: TObject);
var
   poParser : TStringStream;
begin

   if ( IsWindowsVista() )  then
   begin
      SetVistaFonts( self );
   end;

   poParser := TStringStream.Create( gstrSQLParser );

   SQLParser := TSyntaxMemoParser.Create( self );
   SQLParser.RegistryKey := '\Software\Advantage Data Architect\SQLSyntaxMemo';
   SQLParser.UseRegistry := True;
   SQLParser.CompileFromStream( poParser );

   FreeAndNil( poParser );
   poParser := TStringStream.Create( gstrCPPParser );



   cppParser := TSyntaxMemoParser.Create( self );
   cppParser.RegistryKey := '\Software\Advantage Data Architect\SQLSyntaxMemo';
   cppParser.UseRegistry := True;
   cppParser.CompileFromStream( poParser );

   FreeAndNil( poParser );
   poParser := TStringStream.Create( gstrPasParser );

   pasParser := TSyntaxMemoParser.Create( self );
   pasParser.RegistryKey := '\Software\Advantage Data Architect\SQLSyntaxMemo';
   pasParser.Script := ExtractFilePath( Application.ExeName ) + 'pasScript.txt';
   pasParser.CompileFromStream( poParser );

   {* Free the stream since we are finished with it. *}
   FreeAndNil( poParser );

   poCodeOutput := TSyntaxMemo.Create( self );
   poCodeOutput.Parent := Panel1;
   poCodeOutput.Left := 8;
   poCodeOutput.Top := 8;
   poCodeOutput.Width := Panel1.Width - 16;
   poCodeOutput.Height := Panel1.Height - 16;
   poCodeOutput.ClipCopyFormats := [smTEXT, smRTF];
   poCodeOutput.Font.Charset := ANSI_CHARSET;
   poCodeOutput.Font.Color := clWindowText;
   poCodeOutput.Font.Height := -11;
   poCodeOutput.Font.Name := 'Courier New';
   poCodeOutput.Font.Style := [];
   poCodeOutput.GutterFont.Charset := DEFAULT_CHARSET;
   poCodeOutput.GutterFont.Color := clWindowText;
   poCodeOutput.GutterFont.Height := -11;
   poCodeOutput.GutterFont.Name := 'MS Sans Serif';
   poCodeOutput.GutterFont.Style := [];
   poCodeOutput.HyperCursor := crDefault;
   poCodeOutput.IndentStep := 1;
   poCodeOutput.Margin := 2;
   poCodeOutput.Modified := False;
   poCodeOutput.MonoPrint := True;
   poCodeOutput.Options := [smoSyntaxHighlight, smoPrintWrap, smoPrintLineNos, smoPrintFilename, smoPrintDate, smoPrintPageNos, smoAutoIndent, smoTabToColumn, smoWordSelect, smoShowRMargin, smoShowGutter, smoShowWrapColumn, smoTitleAsFilename, smoProcessDroppedFiles, smoBlockOverwriteCursor, smoShowWrapGlyph, smoColumnTrack, smoUseTAB, smoSmartFill, smoOLEDragSource];
   poCodeOutput.ReadOnly := False;
   poCodeOutput.RightMargin := 80;
   poCodeOutput.SaveFormat := sfTEXT;
   poCodeOutput.ScrollBars := ssBoth;
   poCodeOutput.SelLineStyle := lsCRLF;
   poCodeOutput.SelStart := 3;
   poCodeOutput.SelLength := 0;
   poCodeOutput.SelTextColor := clWhite;
   poCodeOutput.SelTextBack := clBlack;
   poCodeOutput.TabDefault := 4;
   poCodeOutput.TabOrder := 0;
   poCodeOutput.VisiblePropEdPages := [ppOPTIONS, ppHIGHLIGHTING, ppKEYS, ppAUTOCORRECT, ppTEMPLATES];
   poCodeOutput.WrapAtColumn := 0;
   poCodeOutput.OnKeyDown := FormKeyDown;
   poCodeOutput.ActiveParser := 3;
   poCodeOutput.Anchors := [akLeft, akTop, akRight, akBottom];
   poCodeOutput.Parser1 := pasParser;
   poCodeOutput.Parser2 := cppParser;
   poCodeOutput.Parser3 := SQLParser;

   SQLParser.AttachEditor( poCodeOutput );
   cppParser.AttachEditor( poCodeOutput );
   pasParser.AttachEditor( poCodeOutput );

   poCodeOutput.Lines.AddStrings( poCode );

   if ( CodeType = ctCPP ) then
      poCodeOutput.ActiveParser := 2
   else if ( CodeType = ctPascal ) then
      poCodeOutput.ActiveParser := 1
   else
      poCodeOutput.ActiveParser := 3;

   MainForm.AdjustFormSize( self, 0.95, 0.75 );
end;
+3  A: 

Is Win32 defined, could the constants be from all the included units.

i would do a binary search: keep tearing half the unit out until it compiles, then add stuff back in.

Yes it sucks, but that's one of the features of trying to debug BorlandCodeGaembarcadero's internal compiler errors.

Ian Boyd
A: 

I've found the method (FormCreate) that is the problem and have been refactoring but no matter how small I make the chunks the compiler still has a problem unless I delete some of the code.

François thanks, but I did refactor the code and still get the error. If it built with D2007, and doesn't with D2009, that seems fishy to me.

procedure TOutputCodeForm.FormCreate(Sender: TObject);
begin

   if ( IsWindowsVista() )  then
   begin
      SetVistaFonts( self );
   end;

   SetupParser( SQLParser, gstrSQLParser, '' );
   // unresolved jmu - have to comment this out for now or delphi will complain
   // that there are too many literals in this file. Seems like a delphi bug
   // since this builds in older versions, and I've already refactored it.
   //SetupParser( cppParser, gstrCPPParser, '' );
   SetupParser( pasParser, gstrPasParser, ExtractFilePath( Application.ExeName ) + 'pasScript.txt' );
   SetupCodeOutput( poCodeOutput );

   SQLParser.AttachEditor( poCodeOutput );
   cppParser.AttachEditor( poCodeOutput );
   pasParser.AttachEditor( poCodeOutput );

   poCodeOutput.Lines.AddStrings( poCode );

   if ( CodeType = ctCPP ) then
      poCodeOutput.ActiveParser := 2
   else if ( CodeType = ctPascal ) then
      poCodeOutput.ActiveParser := 1
   else
      poCodeOutput.ActiveParser := 3;

   MainForm.AdjustFormSize( self, 0.95, 0.75 );
end;
Jeremy Mullin
keep cutting until the problem goes away.
X-Ray
i've even seen my problems (never the error you have) originating from inclusion of certain USES statements. if you have no code left, start carving away the USES stmts.
X-Ray
What code do you have to delete for the error to go away? This may be a clue to the issue.
Toby Allen
+2  A: 

Before claiming it's a compiler bug or asking for help, I would seriously try to organize and clean my code.

I would create dedicated routines to be called for each part in FormCreate instead of this massive bag of yours. - SQLParseInit
- cppParseInit
- pasParseInit
- CodeOutPutInit <-+++++ a lot of constants there

And see if 1 in particular is causing problems.

And it would be not bad to build a minimal case, with as few 3rd party dependencies as possible, to allow others to reproduce it, and see if it is indeed a bug or just bad code.
And also remove those $IFDEF... Just provide the actual code that causes this behavior without all the clutter.

Added: As it works in D2007, but not in D2009, I would also double check that all the libraries/3rd party components that you include in your code are correctly migrated to D2009. (drill down that cppParser)

François
A: 

Given the problem is only happening in one of your Delphi compilers / setups, I find myself wondering if it's related to a component installation problem. Have you tried just creating a basic form that uses static versions of all the components you are creating dynamically? (TSyntaxMemoParser, etc).

(Are you running those Delphi versions on separate machines / VM's btw? Can save a LOT of hassle if you use many third-party components and more than one version of Delphi)

Jamo
A: 

From the help:

One or more of your procedures contain so many string constant expressions that they exceed the compiler's internal storage limit. This can occur in code that is automatically generated. To fix this, you can shorten your procedures or declare contant identifiers instead of using so many literals in the code.

So maybe try putting some of those strings in consts or other variables (non local).

Jim McKeeth
A: 

I'd look at the line of "poCodeOutput.Options := [xx....]" Looks like too many options in the set on one line of code.

Take that one line out and see if you get the error.

Darian Miller