为什么我会收到“太多局部常量”错误?

时间:2008-10-28 17:08:18

标签: delphi delphi-2009 advantage-database-server

Delphi 2009抱怨E2283错误:[DCC错误] outputcode.pas(466):E2283太多局部常量。使用较短的程序

Delphi 2007编译得很好。我找不到丰富的局部常数,它是一个短(500行)单位。你看到我能解决的任何丰富的常量或文字吗?

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;

6 个答案:

答案 0 :(得分:3)

是否定义了Win32,常量是否可以来自所有包含的单位。

我会进行二元搜索:继续撕掉一半的单位直到它编译,然后重新添加内容。

是的很糟糕,但这是尝试调试BorlandCodeGaembarcadero内部编译器错误的功能之一。

答案 1 :(得分:3)

在声称它是编译器错误或寻求帮助之前,我会认真地尝试组织和清理我的代码。

我会为FormCreate中的每个部分创建专门的例程,而不是你的这个庞大的包。 - SQLParseInit
- cppParseInit
- pasParseInit
- CodeOutPutInit< - +++++那里有很多常量

看看1是否特别导致问题。

建立一个最小的案例,尽可能少的第三方依赖,允许其他人重现它,看看它确实是一个错误或只是坏代码,这也不错。
并删除那些$ IFDEF ...只需提供导致此行为的实际代码,而不会造成任何混乱。

补充:由于它在D2007中有效,但在D2009中没有,我还要仔细检查您代码中包含的所有库/第三方组件是否正确迁移到D2009。 (向下钻取cppParser)

答案 2 :(得分:0)

我发现问题的方法(FormCreate)并且一直在进行重构,但无论我编写多少小块,编译器仍然存在问题,除非我删除了一些代码。

François谢谢,但我确实重构了代码并仍然得到了错误。如果它是用D2007制造的,而不是D2009,那对我来说似乎很可疑。

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;

答案 3 :(得分:0)

鉴于问题只发生在你的一个Delphi编译器/设置中,我发现自己想知道它是否与组件安装问题有关。您是否尝试过创建一个使用动态创建的所有组件的静态版本的基本表单? (TSyntaxMemoParser等)。

(你是在不同的机器上运行那些Delphi版本/ VM的btw吗?如果你使用许多第三方组件和多个版本的Delphi,可以节省很多麻烦)

答案 4 :(得分:0)

来自帮助:

  

您的一个或多个过程包含许多字符串常量表达式,它们超出了编译器的内部存储限制。这可以在自动生成的代码中发生。要解决此问题,您可以缩短程序或声明常用标识符,而不是在代码中使用如此多的文字。

所以也许尝试将一些字符串放在consts或其他变量中(非本地)。

答案 5 :(得分:0)

我会看一下“poCodeOutput.Options:= [xx ....]”的行 看起来在一行代码中集合中有太多选项。

取出一行,看看是否收到错误。