Read file by line

General help with the eC language.
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Read file by line

Post by samsam598 »

I am sorry but...

Code: Select all

 
~GetInputFromUser()
{
     delete str;
}
 
With this line the program will crash when accepted console input (file name),FileOpen returned null again;commented out this line will work pretty well.I am confused now. :(
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Read file by line

Post by jerome »

Hi Sam,

Could I see your whole code? I bet you are using your form object after it has been destroyed, e.g.:

Code: Select all

File f;
GetInputFromUser input { };
input.Modal();
f = FileOpen(input.str, read);
Would be wrong, because (at the moment) eC local variables (inside a function/method) start with a reference count of 0.
I plan to fix this in the future (hopefully in 2013 :D), so that they are auto managed just like global and member instances...

So the work around is to manually increment/delete the reference:

Code: Select all

File f;
GetInputFromUser input { };
incref input;
input.Modal();
f = FileOpen(input.str, read);
delete input;
 
Alternatively, you can make the instance a persistent global or member instance.

Regards,

Jerome
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Re: Read file by line

Post by samsam598 »

Bingo!
Appreciated.
Post Reply