5

Delphi 2009 抱怨 E2283 错误:[DCC Error] outputcode.pas(466): E2283 Too many local constants。使用更短的程序

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;
4

6 回答 6

3

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

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

并查看 1 是否特别引起问题。

构建一个最小的案例也不错,尽可能少的 3rd 方依赖项,以允许其他人重现它,并查看它是否确实是一个错误或只是糟糕的代码。
并删除那些 $IFDEF... 只需提供导致此行为的实际代码,而不会造成混乱。

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

于 2008-10-28T20:19:07.023 回答
3

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

我会做一个二分搜索:一直撕掉一半的单元,直到它编译,然后重新添加东西。

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

于 2008-10-28T17:13:59.050 回答
0

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.

于 2008-11-08T04:13:24.033 回答
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;
于 2008-10-28T19:20:20.920 回答
0

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

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

于 2008-10-29T09:21:42.250 回答
0

从帮助:

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

因此,也许可以尝试将其中一些字符串放在 const 或其他变量(非本地)中。

于 2008-10-31T22:35:27.370 回答