#82 On compile pasdoc_package.bpl Delphi xe Fatal Error

0.12.1
closed
5
2014-02-18
2013-03-12
No

Hello!

On compile pasdoc_package.bpl

in module PasDoc_Tipue.pas line

JQueryScript = {$I jquery-1.7.1.min.js.inc};
use file - jquery-1.7.1.min.js.inc

this file not compile with error

[DCC Fatal Error] jquery-1.7.1.min.js.inc(4): F2069 Line too long (more than 1023 characters)

Sorry for my english...

Discussion

    • status: open --> accepted
    • assigned_to: Michalis Kamburelis
     
  • Thanks for reporting!

    I committed a fix. The program tools/file_to_pascal_string.dpr (that is used to generate jquery-1.7.1.min.js.inc from jquery-1.7.1.min.js) now limits the line length in the output.

    So it should compile now under Delphi XE. But I personally don't have access to any Delphi version (I only use FPC/Lazarus), so I can't test this. Can you test compilation of the latest PasDoc version from SVN with Delphi XE, and confirm here that the problem is solved now?

     
  • At Delphi xe found quite interesting limitation.

    If we use the following code:

    const
    JQueryScript = {$I jquery-1.7.1.min.js.inc}; // file is big size...

    procedure Foo;
    var
    str: String;
    begin
    str := JQueryScript;
    end;

    Get an error when compiling -

    [DCC Error] PasDoc_Tipue.pas (234): E2283 Too many local constants. Use shorter procedures

    You can certainly try to load a string from the resource but ... the thing. I'll try to Delphi XE3.

     
    Last edit: Grigoriy Poverenniy 2013-03-13
  • Does the compilation (with Delphi XE) fail even when JQueryScript is a static constant? I mean, not inside a procedure/function, but directly inside unit's implementation section. The error message talks about local constants, suggesting that maybe global ones do not have this limitation.

    For example, can you try to compile this trivial program:

    const
      JQueryScript = {$I jquery-1.7.1.min.js.inc};
    
    begin
      Writeln(JQueryScript);
    end.
    

    If this compiles, then possibly we can workaround the problem by moving inside PasDoc_Tipue the definition of JQueryScript outside of the TipueAddFiles procedure.

     
  • Marcos Rocha
    Marcos Rocha
    2013-09-09

    I'm found a possible solution working on this problem. You can generate tipue search files as resources and include them into final executable.

    The DCC32 documentation says: "The DCC32 and DCCOSX compilers produce E2283 when the code generator gives up after literal/const values exceed 64Kbytes. This 64K limitation applies to string, set, and floating-point values in expressions of a function body, and the limitation is per function."
    http://docwiki.embarcadero.com/RADStudio/XE4/en/E2283_Too_many_local_constants._Use_shorter_procedures_(Delphi)

     
    Last edit: Marcos Rocha 2013-09-09
  • Hm, the resource method could work, but someone has to investigate and test whether it works cross-platform in FPC. Resources were originally a Windows invention. I heard FPC implements them in a cross-platform fashion now, but I honestly don't know how comfortable it is to work with them, what cross-platform tool is available to include a txt file inside a resource file?

    To be clear: I'm not against using resources for this, I just really don't know how well they work cross-platform. And I don't want to break FPC cross-platform compilation just to workaround Delphi-specific limitations.

    Can you send a patch using resources? And can you find a cross-platform tool that we could use to convert text files to resources automatically?

    As for the question in original comment (before editing) :

    Is there any way to copy the minified jquery to destination folder instead of include it in compilation?

    We want to include the file in the executable (as constant or resource) to ease the distribution. So that you can copy pasdoc.exe anywhere and it just works. It's not some extra-critical feature, but it would be a pity to break it just to workaround Delphi limitations.

     
  • Marcos Rocha
    Marcos Rocha
    2013-09-11

    For sure! Actually I've implemented the solution for resource in Delphi yesterday. It's a simple solution for Delphi developers. The resource convertion is made through brcc32.exe aka "Borland Resource Compiler 32".
    I can perfectly understand your worry about working with resources cross-plataform and I'm with you. Including all resources into executable can make pasdoc very portable. So I will do some tests for some weeks with both Delphi and FPC and I'll send you any results after October, 14.

    For a while, these are the steps I have made to reach a solution by now.

    1st. Generate the resource of jquery and other css / js files from tipue search with the brcc32.exe.
    2nd. Include after implementation section the .res directive {$R tipue_search.res}
    3rd. Do a little modification on PasDoc_Tipue as follow:

    {$R pasdoc_tipue.res}
    
    procedure TipueAddFiles(Units: TPasUnits;
        const Introduction, Conclusion: TExternalItem;
        const Head, BodyBegin, BodyEnd: string;
        const OutputPath: string);
    
        //original code here
    
        function ResourceToString(const ResourceName: string): string;
        var
            ResourceStream: TResourceStream;
            ResourceString: TStringStream;
        begin
            ResourceStream := TResourceStream.Create(HInstance, ResourceName, RT_RCDATA);
            ResourceString := TStringStream.Create('');
            try
                ResourceString.CopyFrom(ResourceStream, ResourceStream.Size);
                Result := ResourceString.DataString;
            finally
                FreeAndNil(ResourceString);
                if Assigned(ResourceStream) then
                    FreeAndNil(ResourceStream);
            end;
        end;
    
    const
        TipueSearchCss = 'tipuesearch_css';//{$I tipuesearch.css.inc};
        TipueSearchScript = 'tipuesearch_js';//{$I tipuesearch.js.inc};
        TipueSearchSetScript = 'tipuesearch_set_js';//{$I tipuesearch_set.js.inc};
        JQueryScript = 'jquery_min_js';//{$I jquery-1.7.1.min.js.inc};
        TipueSearchImage : {$I search.gif.inc};
    var
        TipueResultsPage: string;
    begin
        CreateDir(OutputPath + 'tipuesearch');
        StringToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch.css',
            ResourceToString(TipueSearchCss));
        StringToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch.js',
            ResourceToString(TipueSearchScript));
        StringToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch_set.js',
            ResourceToString(TipueSearchSetScript));
        StringToFile(OutputPath + 'tipuesearch' + PathDelim + 'jquery-1.7.1.min.js',
            ResourceToString(JQueryScript));
    
        //original code here
    
     
    • This is very good variant!

       
    • So I will do some tests for some weeks with both Delphi and FPC and I'll send you any results after October, 14.

      Cool, if you could investigate this that would be much appreciated.

      As I see, it works with brcc32.exe and Delphi under Windows. Things that remain to be investigated:
      - is there a cross-platform, preferably open-source, tool to process resources, instead of brcc32.exe.
      - does the above Pascal code work with FPC, cross-platform.

      Actually, I found a page that answers these questions --- http://wiki.freepascal.org/Lazarus_Resources :) See "3 FPC resources". Looks like everything should be perfect, with FPC >= 2.4.0 (which is Ok, we may say that next pasdoc will require at least FPC 2.4.0, since 2.4.0 is already quite old version anyway). So it should be definitely possible to use resources in a cross-platform way with FPC.

      Tests, contributions to commit these changes to pasdoc are most welcome :)

       
      Last edit: Michalis Kamburelis 2013-09-11
  • Marcos Rocha
    Marcos Rocha
    2013-09-24

    How about generate binary files from tipuesearch.css, tipuesearch.js, tipuesearch_set.js and jquery-1.7.1.min.js with file_to_pascal_data.exe and read them with a similar function like WriteGifFile? In that way we can forget the idea of .res files.

     
    • How about generate binary files...

      I thought that this would create the same problem? The size of the binary data produced by file_to_pascal_data will be exactly the same as the size of string produced by file_to_pascal_string (well, sans the fact that file_to_pascal_string changes newlines into OS-dependent NewLine constants).

      Unless the dumb Delphi puts the size limit on strings, but not on arrays of bytes... Which may be true give the documentation you found:

      "The DCC32 and DCCOSX compilers produce E2283 when the code generator gives up after literal/const values exceed 64Kbytes. This 64K limitation applies to string, set, and floating-point values in expressions of a function body, and the limitation is per function."

      I guess it remains to test it, if it works -- Ok :)

       
  • Marcos Rocha
    Marcos Rocha
    2013-09-24

    Great, I will do some tests with that and bring some news soon! I hope we can solve this problem to both FPC and Delphi.

     
  • Marcos Rocha
    Marcos Rocha
    2013-10-08

    Great news people, I've just done my tests on TipueAddFiles and reached the simplest solution which satisfy both FPC and Delphi. However I can't commit the changed unit so follow the steps:

    1) Generate .inc files from tipue using file_to_pascal_data tool.
    2) Change the method TipueAddFiles in PasDoc_Tipue.pas as follow.

        // original code here
        const
            TipueSearchCss : {$I tipuesearch.css.inc}; //Modified Line
            TipueSearchScript : {$I tipuesearch.js.inc}; //Modified Line
            TipueSearchSetScript : {$I tipuesearch_set.js.inc}; //Modified Line
            JQueryScript : {$I jquery-1.7.1.min.js.inc}; //Modified Line
            TipueSearchImage : {$I search.gif.inc};
        var
            TipueResultsPage: string;
        begin
            CreateDir(OutputPath + 'tipuesearch');
            DataToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch.css', TipueSearchCss); //Modified Line
            DataToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch.js', TipueSearchScript); //Modified Line
            DataToFile(OutputPath + 'tipuesearch' + PathDelim + 'tipuesearch_set.js', TipueSearchSetScript); //Modified Line
            DataToFile(OutputPath + 'tipuesearch' + PathDelim + 'jquery-1.7.1.min.js', JQueryScript);//Modified Line
        // original code here
    
     
    Last edit: Marcos Rocha 2013-10-08
    • status: accepted --> closed
     
  • Thank you, I applied the solution to pasdoc sources!