Recent

Author Topic: Wrong number of Parameters?  (Read 692 times)

OC DelGuy

  • Full Member
  • ***
  • Posts: 112
Wrong number of Parameters?
« on: February 04, 2023, 08:05:21 pm »
My compiler is telling me I have the wrong number of parameters (See attachment).   Is that so?  Is it because the first time I used it it was in a "Program" and now I'm using it in an "Application"?
If I enclose the close statement in brackets, then all is fine.  No compile errors.  Like this:
Code: Pascal  [Select][+][-]
  1. {Close(filenameIn);}


But if I leave the close as part of the application, then this happens:
(This is the code that produces the error.
Code: Pascal  [Select][+][-]
  1. unit City;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10.  
  11. {
  12.  
  13.    Types of Settlements will be as follows:
  14.      Hamlets will be no more than 50 Settlers.                                // These are just my notes about the program
  15.      Villages will be no more than 100 Settlers.
  16.      Towns will be no more than 200 Settlers.
  17.      Cities will be no more than 500 Settlers.
  18.      Metropolises will have no limit on Settlers.
  19. }
  20.  
  21. type
  22.   Tgtt = Array [1..3] of String;
  23.  
  24.   TVillage = Packed Record
  25.     Name, Inn, Government : String;
  26.     Gods, Taverns, Trade  : Tgtt;
  27.     Population, Families, Farmers, Artisans, Laborers, Paupers : Integer;
  28.   end; {type Village}
  29.  
  30.  
  31.  
  32. type
  33.  
  34.   { TForm1 }
  35.  
  36.   TForm1 = class(TForm)
  37.     Farmers             : TEdit;
  38.     Artisans            : TEdit;
  39.     Laborers            : TEdit;
  40.     Paupers             : TEdit;
  41.     VillageName         : TEdit;
  42.     Population          : TEdit;
  43.     Families            : TEdit;
  44.     InnSelector         : TListBox;
  45.     TavernSelector      : TListBox;
  46.     TradeSelector       : TListBox;
  47.     Characters          : TListBox;
  48.     CitySelector        : TListBox;
  49.     Memo1               : TMemo;
  50.     InnDescription      : TMemo;
  51.     TavernDescription   : TMemo;
  52.     TradeDescription    : TMemo;
  53.     CharacterDescription: TMemo;
  54.     VilNam              : TStaticText;
  55.     InnDesc             : TStaticText;
  56.     TavDesc             : TStaticText;
  57.     TradSel             : TStaticText;
  58.     TradDesc            : TStaticText;
  59.     Chars               : TStaticText;
  60.     CharDesc            : TStaticText;
  61.     CitySel             : TStaticText;
  62.     Popul               : TStaticText;
  63.     Famil               : TStaticText;
  64.     InnSel              : TStaticText;
  65.     TavSel              : TStaticText;
  66.     Farm                : TStaticText;
  67.     Arts                : TStaticText;
  68.     Labors              : TStaticText;
  69.     Paups               : TStaticText;
  70.  
  71.     procedure FormCreate(Sender: TObject);
  72.   private
  73.  
  74.   public
  75.  
  76.   end;
  77.  
  78. var
  79.   Form1: TForm1;
  80.   Villages : Array [1..1000] of TVillage;
  81.  
  82. implementation
  83.  
  84. {$R *.lfm}
  85.  
  86. { TForm1 }
  87.  
  88. procedure TForm1.FormCreate(Sender: TObject);
  89.   Procedure GetVillageData;  // Get the Village Data.
  90.   Var
  91.     FilenameIn : Textfile;
  92.     Recds, y : Integer;
  93.     Begin {Proc GetVillageData}
  94.       Assignfile(FilenameIn, 'VillageData.txt');
  95.       Recds := 1;
  96.       Try
  97.         Reset(FilenameIn);
  98.         While not EOF(FilenameIn) do
  99.           Begin {While}
  100.             ReadLn(FilenameIn, Villages[Recds].Name);
  101.             ReadLn(FilenameIn, Villages[Recds].Inn);
  102.             ReadLn(FilenameIn, Villages[Recds].Government);
  103.             ReadLn(FilenameIn, Villages[Recds].Population);
  104.             ReadLn(FilenameIn, Villages[Recds].Families);
  105.             ReadLn(FilenameIn, Villages[Recds].Farmers);
  106.             ReadLn(FilenameIn, Villages[Recds].Artisans);
  107.             ReadLn(FilenameIn, Villages[Recds].Laborers);
  108.             ReadLn(FilenameIn, Villages[Recds].Paupers);
  109.           For y := 1 to 3 do
  110.             Begin {For y := 1 to 3 do}
  111.               ReadLn(FilenameIn, Villages[Recds].Gods[y]);
  112.               ReadLn(FilenameIn, Villages[Recds].Taverns[y]);
  113.               ReadLn(FilenameIn, Villages[Recds].Trade[y]);
  114.             end; {For y := 1 to 3 do}
  115.             Recds := Recds + 1;
  116.           end; {While}
  117.  
  118.         Close(FilenameIn);
  119.       finally
  120.       end; {Try Finally}
  121.     End; {Proc GetVillageData}
  122.  
  123. begin {Proc FormCreate}
  124.  
  125. end; {Proc FormCreate}
  126.  
  127. end.
  128.  
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

WooBean

  • Full Member
  • ***
  • Posts: 179
Re: Wrong number of Parameters?
« Reply #1 on: February 04, 2023, 08:15:29 pm »
Hi,
try CloseFile instead.
Your "close" refers now (inside GUI application) to 'TForm1.Close which is with no parameters.
« Last Edit: February 04, 2023, 08:18:49 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

lucydog11

  • Newbie
  • Posts: 3
Re: Wrong number of Parameters?
« Reply #2 on: February 04, 2023, 08:19:51 pm »

use Closefile(filename);  ..i stead of close(filename)

Thaddy

  • Hero Member
  • *****
  • Posts: 12900
Re: Wrong number of Parameters?
« Reply #3 on: February 04, 2023, 08:27:50 pm »
Close is perfectly fine except when the context is wrong like using with.
You can avoid this by calling system.close() instead of close().
Closefile is an abberation, such that I wonder who I need to hit for that.
(So don't come to Salamanca..)
« Last Edit: February 04, 2023, 08:31:58 pm by Thaddy »
Who is responsable for that!! The caller or the callee.. Out! ya'll, NOW. In UTC time, please, so maybe Yesterday or tomorrow.

WooBean

  • Full Member
  • ***
  • Posts: 179
Re: Wrong number of Parameters?
« Reply #4 on: February 04, 2023, 08:36:15 pm »
Close is perfectly fine except when the context is wrong like using with.
You can avoid this by calling system.close() instead of close().
Closefile is an abberation, such that I wonder who I need to hit for that.

OK, broken glass is perfect except that not in one piece. 
Closefile is only the procedure redefinition just to avoid conflicts with name 'Close' very often spotted in methods.
 
« Last Edit: February 04, 2023, 09:08:03 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

jamie

  • Hero Member
  • *****
  • Posts: 5165
Re: Wrong number of Parameters?
« Reply #5 on: February 05, 2023, 12:08:16 am »
To get to the real reason here, CLOSE is part of the TFORM with which he is in.

The only true wisdom is knowing you know nothing

TRon

  • Hero Member
  • *****
  • Posts: 834
Re: Wrong number of Parameters?
« Reply #6 on: February 05, 2023, 03:47:07 am »
To get to the real reason here, CLOSE is part of the TFORM with which he is in.
Exactly, and in which case you can circumvent that by being explicit and use system.close().

OC DelGuy

  • Full Member
  • ***
  • Posts: 112
Re: Wrong number of Parameters?
« Reply #7 on: February 05, 2023, 07:14:21 am »
I decided to keep it super simple.  I just opened the file in Lazarus IDE typed in F-I-L-E after the close and then compiled that.  It worked and I'm just going to leave it like that.

Thanks Guys!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

PascalDragon

  • Hero Member
  • *****
  • Posts: 4957
  • Compiler Developer
Re: Wrong number of Parameters?
« Reply #8 on: February 06, 2023, 10:35:49 pm »
Closefile is an abberation, such that I wonder who I need to hit for that.
(So don't come to Salamanca..)

That would be the original Delphi developers...

Fred vS

  • Hero Member
  • *****
  • Posts: 2975
    • StrumPract is the musicians best friend
Re: Wrong number of Parameters?
« Reply #9 on: February 06, 2023, 11:24:45 pm »
I decided to keep it super simple.  I just opened the file in Lazarus IDE typed in F-I-L-E after the close and then compiled that.  It worked and I'm just going to leave it like that.

To make simple (and Thaddy happy) just type S-Y-S-T-E-M-. before the close, like this:

Code: Pascal  [Select][+][-]
  1. system.Close(FilenameIn);
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

 

TinyPortal © 2005-2018