Android Question Send a table as copy in a function

Espinosa4

Active Member
Licensed User
Longtime User
Hi,

I've a function which receive a table.

B4X:
sub Filtrar_Tabla(disc_table as sql) as string
Dim S as string
.
.
.
.
.
Return s
end sub



The program give an error (too much files open because I call this function many times)
It seems that disc_Table is the original table and not a local variable which disappears every time the function ends.

If before return s I write this sentence: disc_table.close I'm closing the principal Table.

Can I send a variable as copy from another?
In Delphi it was by reference or by value.

Thank you very much in advance for your help.

Cheers
 
Last edited:

emexes

Expert
Licensed User
Longtime User
It seems that disc_Table is the original table
It is a pointer (reference) to the original table. Any operations you do with it, are being done with the original table.

and not a local variable which disappears every time the function ends.
It is not a local copy of the database.

If before return s I write this sentence: disc_table.close I'm closing the principal Table.
Which confirms that it is a pointer (reference) to the original table, and that any operations you do with it, are being done with the original table.

The program give an error (too much files open because I call this function many times)
These two feel unrelated. Can you temporarily do something like:

B4X:
sub Filtrar_Tabla(disc_table as sql) as string
Return "dummy valid return value"    'debugging
Dim S as string
.
.
.
Return s
end sub

and see if the "too much files open" error still occurs?

If it does, then it is being caused by something else in your program, ie not by passing a disc_table here.

If it doesn't, then have a close look at the ". . ." code in the Filtrar_Tabla Sub at the file (or SQL?) operations.

Remember to comment out or delete the extra line after you've finished this test - in the heat of debugging battle, it'd be easy to forget to do this (or maybe it's just me that shoots myself in the foot like that). 🍻
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Consider to pass a resultset and close after using it.
Better to pass a map, list or custom type and close the resultset before passing the object.
 
Upvote 0

Espinosa4

Active Member
Licensed User
Longtime User
It is a pointer (reference) to the original table. Any operations you do with it, are being done with the original table.


It is not a local copy of the database.


Which confirms that it is a pointer (reference) to the original table, and that any operations you do with it, are being done with the original table.


These two feel unrelated. Can you temporarily do something like:

B4X:
sub Filtrar_Tabla(disc_table as sql) as string
Return "dummy valid return value"    'debugging
Dim S as string
.
.
.
Return s
end sub

and see if the "too much files open" error still occurs?

If it does, then it is being caused by something else in your program, ie not by passing a disc_table here.

If it doesn't, then have a close look at the ". . ." code in the Filtrar_Tabla Sub at the file (or SQL?) operations.

Remember to comment out or delete the extra line after you've finished this test - in the heat of debugging battle, it'd be easy to forget to do this (or maybe it's just me that shoots myself in the foot like that). 🍻
Hi @emexes

Thank you so much for your answers. I really appreciate it. I'll try what you mentioned.

This info is very very useful for me.
Now I understand where is my problem.

Best regards
 
Upvote 0
Top