Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

Read file by line
http://ec-lang.org/community/viewtopic.php?f=1&t=339
Page 2 of 2
Author:  samsam598 [ Mon Nov 26, 2012 4:43 am ]
Post subject:  Re: Read file by line

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. :(
Author:  jerome [ Mon Nov 26, 2012 5:11 am ]
Post subject:  Re: Read file by line

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
Author:  samsam598 [ Mon Nov 26, 2012 8:02 pm ]
Post subject:  Re: Read file by line

Bingo!
Appreciated.
All times are UTC-05:00 Page 2 of 2