Limitation of number forms in Basic4PPC

mozaharul

Active Member
Licensed User
I previously posted a problem concerning the application not being able to be loaded on the device. This problem was solved by using the DLL CEnhancedForm.cs, provided by Erel. Since than we were able to load the program. Since the applications was designed for a device with non VGA screen, forms had to be redesigned for a device with VGA screen (for HP ipaq 214) which lead to a increase of Forms to total of 82 Forms. Together with a database there is no problem in loading the application on the device. At any time a maximum of 4 forms are open, and after moving to the next form, the previous form is closed. I am using the hardware library to monitor usage and release of memory. Although, I close the previous form after moving to the next form, the memory allocation is increased with the same number of forms open. After having opened the 25th form, the application stops, showing the message “outofmemoryexceptioncontinue?”. Memory allocation at this point is about 1,020,000 (not sure of the unit).
Restarting the device helps only to move forth 2 more forms before the same message appears.

If we move back and forth the screens a few times, memory allocation increases, even beyond the 1,020,000 at which the application stops.

I attached the application, database, two JPG/GIF file.

Please help,

Regards,
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Although, I close the previous form after moving to the next form, the memory allocation is increased with the same number of forms open.

Regards,

On the device NO forms are closed, but only hidden, after first show...
 

mozaharul

Active Member
Licensed User
So, if it is not possible to release member by closing forms, how to handle this amount of forms in an application?
 

Cableguy

Expert
Licensed User
Longtime User
One Option Would be to simulate a Form using panels...
Since panels are a forms control, it should be loaded at the app start, so the memory usage should stay more or less linear with this solution, as long as it does Start...
This way, all the memory alocation done in every formx.show, would have already been done.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that the allocated memory you get from the hardware library, only returns the "managed" part of the memory used.
Therefore it is not a good indicator for the real memory usage.

When you start a program, all forms are created. So both the number of forms and the number of shown forms affect the memory usage.
Cableguy's suggestion is a good option.
Another option you could try is to use some 'template' forms and at runtime change their layout by showing and hiding controls and setting their positions.

From what I've seen in your application it looks like you can "merge" many forms.
 

mozaharul

Active Member
Licensed User
I have now use a template Form and have created all controls at run time. I have used three sub programs, one to create the controls for each Form (Creat_controls_in_virtualFormX), one to make visibility of controls True (virtual_FormXControls_ON) and one to make visibility False (virtual_FormXControls_OFF). Before switching to another Form, making the visibility of controls of current Form False and visibility of controls of the switched Form True using the respective subs. But switching back and forth takes 6/7 seconds on the device. Only once I found the switching time near about 1.5 seconds (don’t know why). But then again it becomes 6/7 seconds. Although the last Form is having a few controls as you can see in the attached application, it takes same amount to time. How to reduce the switching time between Forms ? I guess that as I move forward to make more controls, using visibility True and False will take more and more time for switching. I tried without the database, its the same. sorry I could not attach the application and other stuff due to the Internet problem.



Regards,
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
how mani controls are you switching ON/Off at a time?
post a list of forms, controls and depedencies and I will make my own code to find a possible solution.
ie:
Vform1 has 10 textboxes 2 buttons 1 image
vform2 has 3 textboxes, 4 labels,2 buttons....
 

mozaharul

Active Member
Licensed User
Thank you very much for your time.

Since I can not attach the application due to the Internet problem, from the first post attached you can have the number of controls I create at run time per Form/page exactly the same as in the physical page/Form. To generate the controls at run time, I wrote the code for Form1, Form1a, Form2, Form3, Form3a, Form4 and Form4a (partly) using the physical properties of controls as it is in the physical Form.

Best regards,
 

Cableguy

Expert
Licensed User
Longtime User
I cannot run the sample code, as it errors but I can see the code...
I will try in the next few days to reproduce the app using panels, but I need some sort of guidelines to what this app does...
It seems to be just a sort of "survey" questionary, but I cannot understand why you are populating the comboboxes in runtime, why "clear" subs for independent textboxes and other control, when only one would do the job...
This app, if I recall correctly, was started using b4ppc 6.30, so I think that all the advantages brought to us with b4ppc 6.50, are not implemented, and would make this app much more readable...
 

Cableguy

Expert
Licensed User
Longtime User
I've starting reproducing all the Forms, Using only 1 BaseForm And adding Panels as Virtual Forms...
So Far I've duplicated Form1 And Form1a, so far so good.
I'm creating ALL controls in runtime except for the baseForm....
I'm also keeping the Controls Names the same so that the Interaction code will be simple copy/paste (I hope)...
If I have counted correctly, there are 83 diferent forms...
Over 1200 labels, in total, almost(?) 2000 controls to replicate...
Its going to be quite a task...
Still there is one thing puzzling me...
You kept the Control bar but hide the Menu bar, making impossible the SIP to show whenever an imput control get the focus...
What device are you targeting?
How will the user input the data?
 

mozaharul

Active Member
Licensed User
I have split up the application (83 Forms) according to their subjects and made different EXE that creates controls at run time. All these EXE will be used one after another each time to collect information about a deceased and a record will be created in the database (kamlapur_va). The VA_Final (in attached application) is the main program. If a “cid” in the “Front3’ (Form) of VA_Final has been selected, it will be saved in the database and “Front4” Form will be shown having all buttons. Each button launches a specific EXE. I have use two separated database, from one database (matlab_va) a specific deceased will be selected and using all EXE data will be collected and saved in another database (kamlapur_va) for the same deceased. A common table named “common” having a single column (“cid’) is used to let different EXEs to know about the current deceased “cid”. Each EXE will save specific data in the respective columns of ‘VA” table and then will write ‘1’ in the respective column (each column represents a EXE) of another table named “EStatus” to indicate a specific EXE has been used (in the attached application, it is done only for respondent and interviewer EXE as test basis). Finally After creating a record using all EXEs the “cid” value will be deleted from the “common” table to start for new deceased.


Along with VA_Final., I attach two other child application, VA_Resp, VA_Interviewer.

Now the problem, since the “common” table will have on value after a record is finished, if a “cid” is selected in “Front3” and back to “Front3” again from “Front4” using "btnfront4prev_Click" event without entering any data then the “cid” saved in the database should be deleted. That works fine on the desktop, but gives error on the device saying :“ InvalidCastException”. I tried my best to understand the cause but could not make it out. Please correct me.

I'm using HPiPAQ 214 PDA (624 Mhz Pro, 128 MB RAM, 256 ROM with VGA display)

Regards,
 

willisgt

Active Member
Licensed User
I ran into this problem last March, with a VGA device (an HP iPaq 210) when we first tried to run an app that was designed primarily for the HTC TyTn (a QVGA device). The limit of the number of forms which could be loaded, naturally, is limited by the mobile device's available memory. On the specific device I was working with, the limit was about 40 forms. 38, if I remember correctly. Add one more form, and POOF - no worky. Program crashed.

The solution - and it was a painful one - was to create almost every form dynamically when it was needed and dispose of it - and every control on it - when the form was closed. Keeping track of all those dynamic forms and controls was a challenge.

Notice I said 'almost every form'. Certain forms - the ones you absolutely know will be needed - weren't created dynamically. So I suppose I came up with a hybrid solution.

I have tested a prototype that creates everything dynamically on five blank forms. I have to keep track of which forms are in use, and the controls placed on each one, but it works. Of course, it could be scaled up to ten or twenty forms, but I can't imagine why a program would need a hierarchy that deep.

Gary
 

mozaharul

Active Member
Licensed User
Thanks for sharing. My approach is bit different, divided the whole application into separate EXEs. Each EXE will know about the current individual form the column value of a common table. Column value will be deleted when a individual in done. But facing problem running it on the device (as I attached). Expecting help from Basic4PPc wizards.

best regards,
 

mozaharul

Active Member
Licensed User
As I explained in the post on 12/28/2008, the application attached works fine on the desktop, but gives error on the device saying :“ InvalidCastException”.

regards,
 

agraham

Expert
Licensed User
Longtime User
I am trying to use my OptimisedDebug app to find the line that gives the error on the device. However as posted your app doesn't seem to work - it gives an SQLite error - so I can't do anything :(

Run app -> Press Matlab -> Press Adult and Elderly Deaths -> SQLite error no such table: matlab

I'm using HPiPAQ 214 PDA (624 Mhz Pro, 128 MB RAM, 256 ROM with VGA display)
So am I :)
 
Last edited:

mozaharul

Active Member
Licensed User
sorry! the database path in the VA_Final application should be :

dbpath="C:\Documents and Settings\mozaharul\Desktop"
' dbpath="\my documents"

it was :

' dbpath="C:\Documents and Settings\mozaharul\Desktop"
dbpath="\my documents"


regards,
 

agraham

Expert
Licensed User
Longtime User
That's a desktop setting, and that path is obviously not present on my machine but it gave me the clue for the device. The error is on line 219 of VA_Final in btnfront4prev_click

If table3.Cell("respo",0)="" Then

which compiles to the C# code

if ((string)__main_table3.GetCell(@"respo",(int)(0d),true)==@"")

You can also replicate this error on the desktop by optimising compiling the code. The error description there is more complete

"Unable to cast object of type 'System.DBNull' to type 'System.String'.

The problem is probably that the cell contains a null value rather than an empty string.
 
Top