B4J Question For Each as map in list Not Working?

MrKim

Well-Known Member
Licensed User
Longtime User
I have been using the same technique without issues for a while, now suddenly it is not working on one particular data set.
Dim LL As List = req.DBResultToMap(res) sets the map
I added this line for testing and as you can see the first Map is there:
1622460835536.png


But when I step to the next line I get my map is not initialized:
1622460965647.png

To be clear Dim Crsr As Map = LL.Get(0) was added only as a test because the the For Each was failing.
I have used this technique a dozen times before in this project and the others all work fine.
The only difference I can see is the data returned contains some large(for me) strings with a lot of CRLFs as you an see in the first shot.

Any ideas greatly appreciated.
 

MrKim

Well-Known Member
Licensed User
Longtime User
I'm sorry, I know I started the response to this but evidently it never got posted. Once again the failure was mine. It was a misspelling on my part.
HOWEVER
This is still an interesting issue. I was led down the wrong path because the Map shows as not initialized.
I have included a program that demonstrates the issue. B4X Pages, but only tested in b4J.

Dim Crsr As Map = LL.Get(0) Works:
1623233052006.png

For Each Crsr As Map In LL Shows as not initialized, however it DOES work (When you don't misspell the field name?).
1623233158016.png
 

Attachments

  • MapIssue.zip
    26.9 KB · Views: 176
Upvote 0

agraham

Expert
Licensed User
Longtime User
It does look like a bug in the Debug code. It seems to think Crsr is always one behind what it actually is. Step round the loop and you will see what I mean
First pass is empty, second pass is what should be the first and so on. I can't see a reason for this in the generated code - not surprisingly as, like you say, it works! Possibly because Crsr is a loop variable and debug is assuming it is somehow different. If you do the following and break after the Log then M displays as expected but Crsr doesn't.
B4X:
            For Each Crsr As Map In LL
                M = Crsr
                Log(Crsr.Get("Ra_CmdName"))
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
It does look like a bug in the Debug code. It seems to think Crsr is always one behind what it actually is. Step round the loop and you will see what I mean
First pass is empty, second pass is what should be the first and so on. I can't see a reason for this in the generated code - not surprisingly as, like you say, it works! Possibly because Crsr is a loop variable and debug is assuming it is somehow different. If you do the following and break after the Log then M displays as expected but Crsr doesn't.
B4X:
            For Each Crsr As Map In LL
                M = Crsr
                Log(Crsr.Get("Ra_CmdName"))
Thanks for taking a look. As I mentioned in post 4 it is not really an issue for me since it works. When I see an anomaly I like to post them even if I have a workaround primarily because I have no idea if it is a symptom of something bigger that might need to be looked at.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
When I see an anomaly I like to post them even if I have a workaround primarily because I have no idea if it is a symptom of something bigger that might need to be looked at.
Quite right too! In this case I do think it might be regarded as a bug so I have posted it as such.
 
Upvote 0
Top