Results 1 to 5 of 5

Thread: Value parameters won't compile?

  1. #1

    Value parameters won't compile?

    I thought I had them working in FPC before... tried to do it in one of my programs and it's a no-go; so I went right to the horses mouth.

    http://www.freepascal.org/docs-html/...2-14200011.4.1

    Their example code

    Code:
    program testp;  
      
    Const  
      MyConst = 20;  
      
    Procedure MyRealFunc(I : Integer = MyConst);  
      
    begin  
      Writeln('Function received : ',I);  
    end;  
      
    begin  
      MyRealFunc;  
    end.
    Will NOT compile here in 2.4.4 -- Win 7 x64 in either the x64 or x86 versions of the compiler.

    test.pas(6,34) Fatal: Syntax error, ")" expected but "=" found

    I really don't want to have to write two versions of the same function on this.
    Last edited by deathshadow; 22-08-2011 at 11:09 AM.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  2. #2
    My bad, it only works when {$mode Delphi} is set. WISH they said that somewhere on said page No... they had to put it on the PREVIOUS page.
    Last edited by deathshadow; 22-08-2011 at 11:31 AM.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  3. #3
    Weird, it compiles for me perfectly fine.

    Lazarus 0.9.31 , FPC 2.4.3, Win7 32bit

    Maybe you're missing some compiler option if directly using fpc. Lazarus is inserting alot of them when compiling.

    edit: Oops, actually it's giving RunError(103) when trying to run it. Stopping on the Writeln(
    Last edited by User137; 22-08-2011 at 04:54 PM.

  4. #4
    Quote Originally Posted by User137 View Post
    Weird, it compiles for me perfectly fine.
    Lazarus throws it into delphi mode I believe, so it should compile. I can't wrap my head around RAD or visual programming, so I'm working from the command line... 30 years of programming including hand assembling my own machine language -- and I STILL can't grasp visual programming, the VCL, etc, etc... I could JUST barely understand OWL... VCL lost me...

    Quote Originally Posted by User137 View Post
    edit: Oops, actually it's giving RunError(103) when trying to run it. Stopping on the Writeln(
    If you cut/paste from the FPC website, it will bomb on the single quotes as for some screwed up reason, their code block has STYLED quotes instead of straights.

    I'm coming to the conclusion the HTML version of the documentation is ***** USELESS!
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

  5. #5
    No it's in objfpc mode
    Code:
    program Project1;
    
    {$mode objfpc}{$H+}
    
    Const
      MyConst = 20;
    
    Procedure MyRealFunc(I : Integer = MyConst);
    begin
      Writeln('Function received : ',I);
    end;
    
    begin
      MyRealFunc;
    end.
    But like said i don't know what i'm doing wrong, because the app doesn't run even if i do this:
    Code:
    program Project1;
    
    {$mode objfpc}{$H+}
    
    Procedure MyRealFunc;
    var i: integer;
    begin
      i:=1;
      Writeln('Function received : ',i);
    end;
    
    begin
      MyRealFunc;
    end.
    Compiler messages are real though, wrong changes in code do result in errors.

    edit: AH! Now they run. I disabled -WG from project options so that it doesn't try to make it Win32 GUI application. From command prompt i get:
    Code:
    Function received : 20
    Last edited by User137; 23-08-2011 at 02:07 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •