Recent

Author Topic: Assign (textfile) not compiling - sometimes.  (Read 1726 times)

teresa

  • New Member
  • *
  • Posts: 19
Assign (textfile) not compiling - sometimes.
« on: April 18, 2024, 01:44:26 am »
Is there a bug in text file handling?  FPC 3.2.2, Lazarus 3.2 - recently updated.

I have a few hundred lines of code. In the global variables there is
Code: Pascal  [Select][+][-]
  1.    {$DEFINE debug}
  2.  
  3.    {$IFDEF debug}
  4.    debugfile: Text;
  5.    {$ENDIF}
and later:
Code: Pascal  [Select][+][-]
  1.    {$IFDEF debug}
  2.    assign(debugfile, 'overfs.debug'); // problem here
  3.    rewrite(debugfile);
  4.    {$ENDIF}
(I'm doing it this way because I need to collect a whole lot of data - more than I want to see in the debugger.)
   
The editor is perfectly happy to suggest completions for the assign - for example suggesting Assign(out t: text; const c: shortstring);

But the compiler has other ideas:
   
Code: Pascal  [Select][+][-]
  1. unit1.pp(343,36) Error: (3026) Wrong number of parameters specified for call to "Assign"
  2. /usr/local/lib/fpc/3.2.2/units/x86_64-linux/rtl/classes.ppu:persist.inc(104,23) Error: (5088) Found declaration: Assign(TPersistent);

(That declaration is the first in the list offered by the code editor. but not the one for today.)

I have worked around this issue with a stringlist, but what is happening? Enquiring minds etc.

TRon

  • Hero Member
  • *****
  • Posts: 2675
Re: Assign (textfile) not compiling - sometimes.
« Reply #1 on: April 18, 2024, 01:48:13 am »
replace
Code: Pascal  [Select][+][-]
  1.    {$IFDEF debug}
  2.    assign(debugfile, 'overfs.debug'); // problem here
  3.    rewrite(debugfile);
  4.    {$ENDIF}
with
Code: Pascal  [Select][+][-]
  1.    {$IFDEF debug}
  2.    system.assign(debugfile, 'overfs.debug'); // problem here
  3.    rewrite(debugfile);
  4.    {$ENDIF}
Probably better to prefix all system related routines, just in case.

The issue is that the code is probably situated somewhere in a control/component/form and there (in that scope) assign means something else.

teresa

  • New Member
  • *
  • Posts: 19
Re: Assign (textfile) not compiling - sometimes.
« Reply #2 on: April 18, 2024, 01:56:13 am »
Thanks TRon - the code is  indeed in a button click event.

Good to be reminded!

bytebites

  • Hero Member
  • *****
  • Posts: 644
Re: Assign (textfile) not compiling - sometimes.
« Reply #3 on: April 18, 2024, 07:12:17 am »
Or use AssignFile and CloseFile procedures from the SysUtils.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6754
Re: Assign (textfile) not compiling - sometimes.
« Reply #4 on: April 18, 2024, 08:18:31 am »
Or use AssignFile and CloseFile procedures from the SysUtils.

Curiously, I don't see those indexed in the RTL documentation.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dsiders

  • Hero Member
  • *****
  • Posts: 1105
Re: Assign (textfile) not compiling - sometimes.
« Reply #5 on: April 18, 2024, 08:51:13 am »
Or use AssignFile and CloseFile procedures from the SysUtils.

Curiously, I don't see those indexed in the RTL documentation.

MarkMLl

None of the procedure or functions in objpas.pp are indexed or generated in the documentation. Probably because they're wrapped with $ifdefs that weren't defined when the docs were built. My guess.

[Edit]
And I just checked... they are present in the FPDoc xml file.
« Last Edit: April 18, 2024, 08:55:33 am by dsiders »
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Thaddy

  • Hero Member
  • *****
  • Posts: 14616
  • Sensorship about opinions does not belong here.
Re: Assign (textfile) not compiling - sometimes.
« Reply #6 on: April 18, 2024, 10:51:18 am »
Or use AssignFile and CloseFile procedures from the SysUtils.
Those two do not belong there. They are simple aliases to system.assign() and system.close().
Should never have been introduced unless Delphi has them.

Hiding them from being documented in a wood of ifdefs is actually a good idea.... O:-)  Brilliant!
« Last Edit: April 18, 2024, 10:59:38 am by Thaddy »
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

Bart

  • Hero Member
  • *****
  • Posts: 5297
    • Bart en Mariska's Webstek
Re: Assign (textfile) not compiling - sometimes.
« Reply #7 on: April 18, 2024, 11:35:37 am »
Those two do not belong there. They are simple aliases to system.assign() and system.close().
Should never have been introduced unless Delphi has them.
And of course Delphi has them, for the reason this thread makes ovious: if you use assign/close in a form's event, you'll get an error.

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 14616
  • Sensorship about opinions does not belong here.
Re: Assign (textfile) not compiling - sometimes.
« Reply #8 on: April 18, 2024, 12:18:09 pm »
That does not make these things any better. It is not Pascal.
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6754
Re: Assign (textfile) not compiling - sometimes.
« Reply #9 on: April 18, 2024, 02:11:48 pm »
Frankly, I am disappointed that such a prominent... in fact vocal if not prolix... member of the community is so dismissive of a relatively inexperienced user's problem, particularly since almost everybody gets caught by this at some point.

Assign() and Close() are a big problem, and while Close() is most often misinterpreted to mean a graphical form Assign() is implemented by fundamental classes including TList and TStringlist.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 14616
  • Sensorship about opinions does not belong here.
Re: Assign (textfile) not compiling - sometimes.
« Reply #10 on: April 18, 2024, 03:16:52 pm »
If it were a beginner I would rephrase it. The one that made the suggestion is no beginner.
Assign() and Close() existed before some idiots mixed up the language without thinking.
Fixing a symptom without analyzing the cause is plain ignorance.
And this is such a case that is not only obvious, but obnoxious. IOW toxic language pollution.
« Last Edit: April 18, 2024, 03:22:25 pm by Thaddy »
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5519
  • Compiler Developer
Re: Assign (textfile) not compiling - sometimes.
« Reply #11 on: April 18, 2024, 09:51:50 pm »
If it were a beginner I would rephrase it. The one that made the suggestion is no beginner.
Assign() and Close() existed before some idiots mixed up the language without thinking.
Fixing a symptom without analyzing the cause is plain ignorance.
And this is such a case that is not only obvious, but obnoxious. IOW toxic language pollution.

Complaining about it doesn't help that AssignFile and CloseFile are the solutions the developers of Delphi had come up with to use in context of working with VCL components. And thus one should suggest teresa to either use those or - as done by TRon - System.Assign and System.Close without doing an unrelevant rant about why the Delphi developers did what.

 

TinyPortal © 2005-2018