Forum > General

Lazarus is a shit about opening text files

(1/2) > >>

Antony:
I have this code

--- Code: ---
                     assignFile(tf, flnm);
                     {$I-}
                       reset(tf);
                     {$I+}
         
                     if IORESULT <> 0
                     then return := ERROR
                     else begin
                                     ....
                            end;

--- End code ---


in a function, and the exact code in another function, BUT, in one of those functions IT DOES NOT WORK

while executing I receive invalid dile handler...

any suggestion?

Adam.Pilorz:
Well, I had never any problems opening text files realy... And on the other hand it is not Lazarus, only Free Pascal Compiler, what can eventualy create such problem. Lazarus is only IDE and graphical component's library, nothing more. I suggest that you should put this question in a Free Pascal forum or mailing list, but first try to compare twice that codes in different situations (try both when the file exist and both, when not).

Lightning:
This was discussed before, search the forum.
I strongly suggest using higher level components, they are easier to use and safer.
See StringList, Memo, etc.
You can load a file with just one line of code, manipulating strings is also verry easy.
Lazarus is as "shit" as Delphi is, personally i find it easy to use for simple tasks like loading files :)

Adam.Pilorz:
Well, using higher level components have one bad thing: You must load whole file to memory, what can be very unwanted when the file is big and you don't need to load all the file to get your informations. But AssignFile works fine to me...

RudieD:
Antony,
Instead of just Reset why don't you use
...
if FileExists(flnm) then  {--
  Reset(tf)  {-- Open File--}
else
  Rewrite(tf); {-- Create File --}
...

Navigation

[0] Message Index

[#] Next page

Go to full version