Delphi 为什么我会得到一个“;太多的局部常量”;错误?

Delphi 为什么我会得到一个“;太多的局部常量”;错误?,delphi,delphi-2009,advantage-database-server,Delphi,Delphi 2009,Advantage Database Server,Delphi 2009抱怨E2283错误:[DCC错误]outputcode.pas(466):E2283本地常量太多。使用更短的程序 Delphi2007编译得很好。我找不到大量的局部常数,这是一个短(500行)单位。你看到我能处理的大量常量或文字了吗 procedure TOutputCodeForm.FormCreate(Sender: TObject); var poParser : TStringStream; begin if ( IsWindowsVista() )

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

Delphi2007编译得很好。我找不到大量的局部常数,这是一个短(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;

是Win32定义的,常量可以来自所有包含的单元

我会做一个二进制搜索:不断删除一半的单元,直到编译完成,然后再添加一些东西

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

我找到了问题所在的方法(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;

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

我会为FormCreate中的每个部分创建专门的例程,而不是你的这个大袋子。 -SQLParseInit
-cpppasseinit
-pasParseInit

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

(您是否在单独的计算机上运行这些Delphi版本/VM的btw?如果您使用多个第三方组件和多个Delphi版本,可以节省大量的麻烦)

来自帮助:

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

因此,也许可以尝试将这些字符串中的一些放入常量或其他变量(非局部变量)。

我将查看“poCodeOutput.Options:=[xx…”行 一行代码中的选项太多


把那一行拿出来,看看你是否得到了错误

继续切割直到问题消失。我甚至看到我的问题(从来没有你的错误)源于包含某些USES语句。如果你没有代码了,开始删除USES stmts。你需要删除什么代码才能消除错误?这可能是问题的线索。我发现了问题。对gstrCPPParser的引用。这个全局字符串是一个巨大的字符串。从内存的角度来看,Delphi 2009的字符串是原来的两倍大(:它有多大?