Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Basic4ppc Wishlist > Bug Reports
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Bug Reports Post about errors or bugs encountered.

Object incorrectly seen a variable by compiler

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2010, 07:59 PM
RacingDog's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Fleet, Hants, UK
Posts: 183
Send a message via Yahoo to RacingDog
Default Object incorrectly seen a variable by compiler

OK, I know we all do it eventually, but I rather belatedly joined in and tried to produce my own trivial shopping list proggy. Except I can't run it because of a compiler error.

In a sub which. hilariously, is virtually identical to a sub a few lines above which doesn't cause an error, an Object is incorrectly reported as a local variable which is never used in the sub (despite being correctly recognised throughout the rest of the program)..

The main prog is only 145 lines, the sub is only 8 lines, so nothing too tricky. and being a compile error, you don't even have to understand how it's supposed to work either. (it's slightly more complex because there is another module, the latest totally untested and un-compiled version of my INIfiles module, so for heavens sake don't anybody try to use that, it probably is a load of rubbish)

I'll try to find a fudge, but it really ought to have a proper fix.

Cheers all.
Attached Files
File Type: sbp Shopping.sbp (4.5 KB, 1 views)
File Type: bas INIFiles.bas (7.7 KB, 2 views)
Reply With Quote
  #2 (permalink)  
Old 07-04-2010, 08:15 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

The error message is entirely correct in this case, in fact you have two errors. You are trying to pass both a string literal (False) and an object property (Item.Text) ByRef but only regular variables can be passed ByRef as neither of the others is represented as a reference to a memory address.

If you really want to pass ByRef this works.
Code:
    textval = Item.Text
falseval = 
False
INIFiles.PutString ( ShoppingIni, Master, textval, falseval )
You will find a further error at line 112 on the second run of the app because of an access error to Shopping.ini. I haven't bothered to look why.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 07-04-2010 at 08:18 PM.
Reply With Quote
  #3 (permalink)  
Old 07-04-2010, 08:34 PM
RacingDog's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Fleet, Hants, UK
Posts: 183
Send a message via Yahoo to RacingDog
Default

No, the error I am getting is on line 140, it is nowhere near that line, it says Node is unused in that sub. I have no idea why you are being given a different error, but it is NOT the one I reported.

But thanks for finding those two, even though they are totally separate from the reported problem.

And yes it is correct for utility routines to have ByRef parameters as passing arrays or records by value is inefficient. I know it doesn't matter in this day and age with fast processors and huge memory, but my lifetime habits are that only incompetent idiots throw chunks of memory around, and I'm too old to change.

Had that error been reported, I wouldn't have needed anyones help fixing it.
Reply With Quote
  #4 (permalink)  
Old 07-04-2010, 09:12 PM
RacingDog's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Fleet, Hants, UK
Posts: 183
Send a message via Yahoo to RacingDog
Default

I just fixed the problems you spotted, plus all the other instances of those problems but........

I still get the problem I originally reported, it is now on line 147.

I had hoped I was just seeing some obscure knock on effect, sadly not.

Why would an object need to be a reference in order to be passed by reference? It is the compiler's job to generate a reference to the passed value. If a numeric literal is passed to a procedure then clearly it cannot be a Ref parameter. Anything else can be because they take up a memory chunk which can be pointed to. A string literal, or anything else, has to live somewhere, that somewhere has an address, that address can be passed as a reference.

Maybe they don't do it in commercial languages, but in real time languages it is not unheard of to specifically have a "constant " qualifier for reference parameters (or whatever the specific language calls them) so that the compiler can trap assignment to the parameter as an error, thus allowing structured contants to be efficiently handled. So, yes, in some languages, a literal string can be passed by reference, just because it is efficient.

But anyway, I digress.

Back to the thread......

The problem is still there, despite sundry corrections.

P.S. What makes you think us old time real timers are obsessive about efficiency? LOL
Attached Files
File Type: sbp Shopping.sbp (4.6 KB, 2 views)
Reply With Quote
  #5 (permalink)  
Old 07-05-2010, 08:32 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by RacingDog View Post
I still get the problem I originally reported, it is now on line 147.
I'm afraid that I didn't get your original error as I had the Tools-> Check for unassigned... option disabled. You should be using "Node.Value = " as the assignment destination otherwise Basic4ppc assumes you are auto-declaring a local variable called "Node".

Quote:
Why would an object need to be a reference ...
In Basic4ppc it just does! Bear in mind that the language is both interpreted and compiled. In fact it started out interpreted only and "grew" a compilation phase only a few versions ago to improve performance. The tokenised version of the code that is interpreted is also used to generate the equivalent code for compilation so trying to ensure that the behaviour in both environments remains the same. A side effect of this is that there are compromises in the compiled code. Because the interpreter treats literals differently to variables and only allows a "proper" variable to be passed by reference that limitation also applies to the compiled version.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #6 (permalink)  
Old 07-05-2010, 10:31 AM
RacingDog's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Fleet, Hants, UK
Posts: 183
Send a message via Yahoo to RacingDog
Default

Dang, knew it would be something obvious. Stared at that for ages and couldn't see it for looking.

Ta. All I have to do now is negotiate the first click problem which is more troublesome than I thought.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error - object reference not set to an instance of an object moster67 Questions (Windows Mobile) 13 02-06-2010 06:43 PM
Local variable cannot hid global variable jschuchert Questions (Windows Mobile) 6 10-30-2009 02:58 PM
Meldung: Local variable cannot hide a global variable JOTHA German Forum 2 07-18-2009 11:34 AM
Object Reference Not Set to an Instance of an object mikewhite Questions (Windows Mobile) 2 02-14-2009 07:21 PM
Object Reference not set to an instance of an object monster9999 Questions (Windows Mobile) 9 01-15-2008 09:56 PM


All times are GMT. The time now is 04:06 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0