Ecere SDK/eC Forums • View topic - Read file by line




Ecere SDK/eC Forums

Ecere Developers Community

Read file by line

General help with the eC language.

Re: Read file by line

Postby samsam598 » Mon Nov 26, 2012 4:43 am

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. :(
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: Read file by line

Postby jerome » Mon Nov 26, 2012 5:11 am

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
jerome
Site Admin
 
Posts: 621
Joined: Sat Jan 16, 2010 11:16 pm

Re: Read file by line

Postby samsam598 » Mon Nov 26, 2012 8:02 pm

Bingo!
Appreciated.
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Previous

Return to eC Language

Who is online

Users browsing this forum: No registered users and 3 guests

cron