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

问题描述:

德尔福2009年抱怨与E2283错误:[DCC错误] outputcode.pas(466):E2283太多局部常量。使用较短的程序为什么我得到“太多局部常量”错误?

德尔福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; 
+1

我发现了这个问题。对gstrCPPParser的引用。该全局字符串是一个字符串的怪物。 – 2009-04-02 17:13:11

+0

和内存方面,字符串在德尔福2009中获得了两倍的增长(:它有多大? – 2012-09-04 14:29:20

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

我会做一个二进制搜索:保持撕裂一半的单位,直到它编译,然后添加的东西回来

是的,它很烂,但是这是试图调试BorlandCodeGaembarcadero的内部编译器错误的功能之一。

我发现了问题并重构了方法(FormCreate),但无论我如何制作块,编译器仍然有问题,除非我删除了一些代码。

弗朗索瓦感谢,但我没有重构代码,仍然得到错误。如果它使用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
- cppParseInit
- pasParseInit
- CodeOutPutInit < - +++++很多常量有

看看是否1特别是造成问题。

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

补充:因为它在D2007中工作,但在D2009中不行,所以我还要仔细检查包含在代码中的所有库/第三方组件是否已正确迁移到D2009。 (钻取该cppParser)

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

(是否运行在不同的机器的德尔福版本/ VM的BTW可以节省麻烦很多,如果你使用许多第三方组件和Delphi的多个版本?)

从帮助:

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.

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

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

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