Recent

Author Topic: [SOLVED] Proper/preferred file options?  (Read 2143 times)

WickedDum

  • Full Member
  • ***
  • Posts: 211
[SOLVED] Proper/preferred file options?
« on: February 04, 2015, 08:10:54 am »
I have seen a lot of ways to read/write to a file.  So many ways, that I would like some clarification from you more experienced types, as well as the best recommendations.   Rework is a pet peeve of mine.  Sooo, I'd rather start reading/writing files in the preferred manor.

1)  The compiler directive {$I}:  I remember using it 30 years ago...(TP1-6; never Delphi).  Not used now in favor of "try...except..."?

2)  Assign?  Assignfile?

3)  Binary files?  UTF8ToSys (OpenDialog...)?  Is this the only way to read/write binary files?

4)  Utilizing "FileMode"?  If I open the file to read it in (FileMode := 0) and then want to add some data, I'll have to modify the FileMode (FileMode := 1).  Isn't that a lot of extra work?  (Again, from my experience 30 years ago...)

It seems to me that all of this complicates coding...  See my dilemma?  Any and all thoughts are appreciated!

Thanks!
« Last Edit: September 01, 2016, 01:57:54 am by WickedDum »
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Proper/preferred file options?
« Reply #1 on: February 04, 2015, 08:44:54 am »
1)  The compiler directive {$I}:  I remember using it 30 years ago...(TP1-6; never Delphi).  Not used now in favor of "try...except..."?
Who says? Even the official docs use it for example. It's completely up to you to use which one.
2)  Assign?  Assignfile?
System.Assign or ObjPas.AssignFile (which is the same thing, just the latter maps to the former). The unit prefix is optional so if you have a name clash but don't want to use the unit prefix, use the other identifier which doesn't clash.
3)  Binary files?  UTF8ToSys (OpenDialog...)?  Is this the only way to read/write binary files?
No. Procedural style assign-reset/rewrite/append-close works on binary files, too. Moreover, UTF8ToSys has nothing to do with binary files.
4)  Utilizing "FileMode"?  If I open the file to read it in (FileMode := 0) and then want to add some data, I'll have to modify the FileMode (FileMode := 1).  Isn't that a lot of extra work?  (Again, from my experience 30 years ago...)
set to fmInOut.

 

TinyPortal © 2005-2018