Recent

Author Topic: Use file commands in Applications  (Read 2158 times)

Cigomi

  • New member
  • *
  • Posts: 8
Use file commands in Applications
« on: May 24, 2016, 02:58:56 pm »
Ok, first of all I am a beginner, so sorry if I seem stupid or newbie :D
I don't even usually speak English, so I could make some mistakes...
ANYWAY
I just started using applications (I mean the ones with buttons and edits) instead of simple projects (I mean those with the black screen and the DOS style text). I knew how to use files before, (for example assign(namefile,'file.fileext')and so on).
Now, when I create a form and write the same instructions, it says I used the wrong numbers of parameters... Why??
Here's the code
--------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
  application.Title:='  1Aid';
  assign(fileElenco,'elenco.dat');
end;       
--------------------------------------------------------
Can you help me, please? Thank you in advance :)       

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Use file commands in Applications
« Reply #1 on: May 24, 2016, 03:07:03 pm »
Either use the full qualified name: System.Assign(fileElenco,'elenco.dat');
or use AssignFile

Cigomi

  • New member
  • *
  • Posts: 8
Re: Use file commands in Applications
« Reply #2 on: May 24, 2016, 03:16:11 pm »
Thank you for the fast answer! :)
Should I do this for reset and close too? And how can I close the file when the Application closes too without doing Runtime errors?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Use file commands in Applications
« Reply #3 on: May 24, 2016, 03:48:39 pm »
You can call Reset without problems.
Borland renamed the file Close procedure CloseFile() at the same time Assign for files was renamed AssignFile(). This was to prevent name clashes with many similarly named VCL methods (and FPC's RTL is Delphi-compatible as far as possible, so adopts the same names and syntax).
It is usually sufficient to call CloseFile in your main form's OnDestroy handler (if you don't call it earlier)
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. begin
  3.   CloseFile(fileElenco);
  4. end;  

If for some reason you need to delay closing the file until the application itself terminates, you can add a line that calls
Code: Pascal  [Select][+][-]
  1.   Application.AddOnEndSessionHandler();  
in your main .lpr file, and remove the handler before the end.

 

TinyPortal © 2005-2018