Italian [B4XPage][B4XDraw][B4J] Differenti Draw in diverse Page

Elric

Well-Known Member
Licensed User
Ciao a tutti!

Stavo cercando di capire come maneggiare i Draws con le pages.

Mi sono imbattuto in questa discussione: https://www.b4x.com/android/forum/threads/b4xdrawer-how-to-make-available-for-each-page.125360/ e seguito il suggerimento di @klaus di prendere spunto dalla NavBar https://www.b4x.com/guides/B4XPagesCrossPlatformProjects/?page=40.

Ho prodotto il progetto allegato ma:
  • sebbene mi carichi il layout del drawer e della pagina, i comandi della pagina non funzionano
  • i pulsanti del drawer mi danno errore (a quanto pare non gli piace la dichiarazione "Private Index as Int"... ma ci sta che abbia capito male io)
Qualcuno ha qualche idea su come fare a far girare il tutto?

Edit1: ovviamente ho provato a fare diverse prove empiriche ma senza successo.
Edit2:New zip file.

Grazie in anticipo!
 

Attachments

  • B4XPage+2 different Drawers.zip
    22.5 KB · Views: 181
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Non ho mai "smanettato" con i drawer (forse mezza volta, giusto per dare una "zampa") ma ho sviluppato una "semplice" libreria B4Xlib partendo da B4A.
Solo in seguito mi sono accorto che con B4J ci sono problemi (e non ho approfondito per risoverli, perché mi sembra che le B4XPages siano più adatte ad Android e iOS che a B4J [Desktop sw].
Il problema (anche se ancora non ho guardato il tuo sorgente ma l'ho scaricato - a proposito, non hai scritto che ti riferivi a b4j e... grrrr... non hai pubblicato il progetto come si dovrebbe fare, ovvero con CTRL+Click sul commento-comando:
B4X:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
dicevo che il problema è che mentre in B4A hai una sola Activity (con le B4XPages, benché anche con queste potresti aggiungere altre Activity ma non ne vale la pena), con B4J e temo anche con B4i non hai una sola base, un solo Form.

Già quando aprii il thread riguardo quella libreria avevo in mente di aprirne un altro proprio su questo argomento; non lo feci ma penso che lo farò presto.

Dò un'occhiata al tuo progetto ma non ti prometto niente alcunché, perché non ho esperienza di Drawer e perché il problema è molto probabilmente quello di cui ti ho appena scritto.
 

LucaMs

Expert
Licensed User
Longtime User
E' un vero macello!

Ogni B4XPage ha i propri eventi. Se, come mi sembra di capire non approfondendo perché il tutto è piuttosto complesso (per non dire complicato), passi una B4XPage ad una classe (mdlDrawer) gli dovresti "passare" (delegare) anche gli eventi di quella B4XPage.
 

klaus

Expert
Licensed User
Longtime User
I had a look at your project.
But:
- What is sp‚cifi this file? I get an error 'sp‚cifi' not found in D:\B4X\Users\Shared Files\. So the project cannot be compiled!
Perhaps it is due to the fact that you did not zip the B4XPages project correctly as already reported by LucaMs.
- I don't understand what exactly you want to do and I don't understand your logic.
- You have B4XPagex modules where you do nothing ! Why ?
- Then you have mdlPagex modules. What are these supposed to do ? These are referenced in the B4XPagex modules but nothing concrete is done!?

Please explain exactly what you want to do and what you expect.
 

LucaMs

Expert
Licensed User
Longtime User
- What is sp‚cifi this file? I get an error 'sp‚cifi' not found in D:\B4X\Users\Shared Files\. So the project cannot be compiled!
Perhaps it is due to the fact that you did not zip the B4XPages project correctly as already reported by LucaMs.
Yes, because of that you "are forced" to comment out the CustomBuildAction (B4XMainPage) to be able to run the project.
 

Elric

Well-Known Member
Licensed User
Grazie! Thank you!

- What is sp‚cifi this file? I get an error 'sp‚cifi' not found in D:\B4X\Users\Shared Files\. So the project cannot be compiled!
Perhaps it is due to the fact that you did not zip the B4XPages project correctly as already reported by LucaMs.
I don't know what "sp‚cifi" is - it's not mine! I swear! 😅 However new zip file correctly created is in the first post. Sorry!
- I don't understand what exactly you want to do and I don't understand your logic.
I'm studying the drawer; I've no problem with the Erel's example. I would like to create a project with a drawer (the drawer1) for page 2 and page 3 and a second drawer (the drawer2) only for page 4 and 5. It is just to understand how drawer works and so implement in some project in the future.
- You have B4XPagex modules where you do nothing ! Why ?
When I studied "TableAndForms" example I noted that the entire project is demanded to EditableTable, including buttons event. So, I thought it was a way to keep clean the project.
- Then you have mdlPagex modules. What are these supposed to do ? These are referenced in the B4XPagex modules but nothing concrete is done!?
This project is only to study purpose. So, the mdlPageX is quite empty and just manage some silly event. It is there only because in future project they may contain more code (such like EditableTable in TableAndForms example).

E' un vero macello!

Ogni B4XPage ha i propri eventi. Se, come mi sembra di capire non approfondendo perché il tutto è piuttosto complesso (per non dire complicato), passi una B4XPage ad una classe (mdlDrawer) gli dovresti "passare" (delegare) anche gli eventi di quella B4XPage.
Il punto è proprio qui. Non è un problema per me creare un drawer per una pagina. L'esempio di Erel (https://www.b4x.com/android/forum/threads/b4x-b4xpages-b4xdrawer.120246/) è abbastanza chiaro per me, ma nell'esempio il drawer appare solo in una pagina. Per avere il medesimo drawer su più pagine viene suggerito:
That's the point. It's not a problem for me programming a drawer in one page. the Erel's example is quite understandable for me, but in such example the drawer appears only in one page. To have the same drawer in more than one page it is suggested:
You can implement the code that builds the drawer in its own class and create a new class instance in each of the pages
You might have a look at the B4XPagesNavBar project in the B4X Cross-platform projects booklet.
It uses a navigation bar at the bottom of each page, it is not exactly what are looking for but it could inspire you.
che è quello che ho cercato di fare con un risultato pessimo. Anzi, mi sa che ho fatto il contrario di quanto suggerito... ma mi sfugge come creare una nuova istanza di classe in ogni pagina.
that is what I try to do with terrible result. Actually, I believe that I did the contrary... but I can't get how create a new class instance in each page.

Chiedo scusa: pensavo che fare lo zip dal menù e cliccare sul link fosse la stessa cosa. Ho fatto zip con il link e aggiornato nel primo post. Mi ero posto il problema se specificare che fosse B4J, ma utilizzando tutto in cross platform pensavo non fosse necessario. Ri-mea culpa.

I'm sorry: I thought that creating zip file from menu and clicking on the link was the same. Now, I make the zip file with the link and update the first post. I asked myself if was necessary specify that the project was in B4J, but programming in cross platform I guess it was not necessary. Again, I'm sorry.
 

LucaMs

Expert
Licensed User
Longtime User
Dovrei guardare di nuovo (e mooolto più attentamente) l'esempio Drawer ma voglio dire che i problemi sono due, non uno:

1 - poter avere un Drawer specifico per qualunque B4XPage tu voglia;
2 - farlo con B4J, dato che questo cambia molto le cose visto che, come detto, mentre in B4A tu hai un'unico elemento base che è l'Activity Main e che conterrà tutte e B4XPage, in B4J ogni B4XPage viene visualizzata nel proprio Form.

P.S. Ho visto che l'esempio di Erel è anche per B4J (ma una sola B4XPage ha ed usa un solo Drawer, che è la questione aperta qui. Proverò partendo da un progetto vuoto).
 
Last edited:

udg

Expert
Licensed User
Longtime User
Guardate questo esempio di Drawer su più pagine.
Comunque, pur non avendola ancora provata, l'idea di creare una classe per il drawer e poi instanziarla su ogni pagina dove si voglia mostarlo mi sembra l'ideale.
Utilizzando il primo sistema, avevo imbastito un'app che mostrava drawer diversi in funzione di chi aveva effettuato il login (in pratica il menu di opzioni mostrato sul drawer dipendeva dal profilo dell'utente); mi restava di passare tutto a classe, ma..ho perso interesse e mi sono dedicato ad altro.
 

Elric

Well-Known Member
Licensed User
Grazie ancora per il supporto e i chiarimenti!

Pensavo fosse una cosa più abbordabile e più "cross".
 

klaus

Expert
Licensed User
Longtime User
Here you are.

In MainPage I added a second button to go to Page4.
From the Main Page you can go either to Page2 or Page4 with Buttons.
On Page2 and Page3 you can go only to MainPage, Page2 and Page3
On Page4 and Page5 you can go only to MainPage, Page4 and Page5
These are managed with the two layouts.
I had to add the Tag properties in the Designer.

Your project structure is not optimal.
All the Page modules and the Drawer module should be in the project folder, the same place as the B4XMainPage module.
And then they should be loaded with a relative link.
Currently, they are in the B4J folder with an absolute link. I have not changed the structure, I leave it up to you.
The advantage with the structure above is:
- Let's say you have the B4J and the B4A IDEs open.
- If you modify one of the modules, for example in B4J, and save the project, the code in the same modules in the B4A IDE will be updated automatically.
 

Attachments

  • B4XPage_2differentDrawersNew.zip
    40.4 KB · Views: 164

Elric

Well-Known Member
Licensed User
Grazie klaus.

Ho visto le tue modifiche: grazie, apprezzo molto il tuo supporto. Capito l'errore.

Due domande:
1.
Se avvio il tuo progetto sul mio pc, i button nella MainPage e i drawer funzionano, mentre i button nel CenterLayout non funzionano. Questo era un problema che avevo notato anche in uno dei miei tanti tentativi. È così anche per te?

2.
Sulla struttura ottimale per i progetti: se ho capito bene, per avere un progetto "cross platform", tutti i moduli devono risiedere nella stessa cartella del modulo B4XMainPage e, quindi, quando aggiungo un nuovo modulo di classe o un nuovo modulo B4XPage devo spuntare "Add to parent folder".

Per lo stesso progetto, negli altre IDE, devo aggiungere gli stessi moduli ma selezionando "relative link", così un solo modulo è automaticamente aggiornato su tutti gli IDE.

Ma come posso usare il comando "Add an existing module" e aggiungere questo modulo nella stessa cartella del modulo B4XMainPage? Questo non mi è chiaro. Se io volessi spostare le B4XPage del mio progetto dalla cartella "B4J", dove sono adesso, alla cartella dove si trova il modulo B4XMainPage come dovrei fare? Forse creare una nuova B4XPage e copiare il codice? (Forse è una domanda stupida ma non saprei come altro fare).


Thank you klaus.

I've seen your modifications: thanks, very appreciated. I've understood my error.

Two questions:
1.
If I run your project on my pc, the buttons in the MainPage and the drawers work, not also the buttons in the CenterLayouts: they don't work. This was a problem I've noted also in one of my attempts. Do you have the same problem?

2.
About the optimal project structure: if I've correctly understood, to get a "cross platform" project, all modules have to stay in the same folder of B4XMainPage module and, then, when I add a new class module or a new B4XPage module I have to check "Add to parent folder".

For the same project, in the other IDEs, I have to add the same modules but selecting "relative link", in this way I'll have one module automatically updated for all the IDEs.

But how I can use the command "Add an existing module" and adding this module in the same folder of of B4XMainPage module? This is not clear for me. Maybe I have to create a new B4CPage and paste the code? (Maybe this is a stupid question but I don't know any other solution).
 

LucaMs

Expert
Licensed User
Longtime User
1. In una mia libreria ho lo stesso problema ma avendola "abbandonata" (perlomeno sospesa) non ho più cercato la soluzione.

2. E' tutto esatto.
Ma come posso usare il comando "Add an existing module" e aggiungere questo modulo nella stessa cartella del modulo B4XMainPage? Questo non mi è chiaro. Se io volessi spostare le B4XPage del mio progetto dalla cartella "B4J", dove sono adesso, alla cartella dove si trova il modulo B4XMainPage come dovrei fare? Forse creare una nuova B4XPage e copiare il codice? (Forse è una domanda stupida ma non saprei come altro fare).
Non c'è modo, devi farlo a mano; ovvero, nel tuo esempio, aprire la cartella B4J, "tagliare" (non copiare) la classe (B4XPage ma vale per qualunque altro modulo) e incollarla in quella che potremmo chiamare la "root dei progetti" (?), cioè allo stesso livello della B4XMainPage. Poi di nuovo importarla nel tuo progetto B4J, spuntando il "relative link".
Si deve fare altrettanto se, ad esempio, tu volessi usare un modulo di codice contente delle tue utility da un progetto del tutto diverso ad un altro.


P.S.
Chiesto come "Wish":
https://www.b4x.com/android/forum/t...ects-root-folder-and-other.126470/post-790596
 
Last edited:

klaus

Expert
Licensed User
Longtime User
1. It is the same on my computer, I hadn't tested them.
Then, I checked your project from post #1 and the buttons on Page2 don't work either.
I will need to look further why this happens.

2. As LucaMs explained.
I don't know, if you leave the modules where they are and you add them in the other platforms with a relative link if they will be dynamically updated.
 

Elric

Well-Known Member
Licensed User
Se dal Designer creo gli eventi dei pulsanti del CenterPanel nel modulo del drawer (mdlDrawer) invece che in qualsiasi altro modulo, allora funzionano...

If I make CenterPanel buttons events in the mdlDrawer module from Designer instead of any other module, then they work...
1610557224592.png

Questo potrebbe voler dire che gli eventi dei due layout (CenterPanel e LeftPanel) devono essere gestiti nel modulo dove è inizializzato il drawer?

This might mean that the events of two layouts (CenterPanel and LeftPanel) should be managed in the module where the drawer is initialized?
 

klaus

Expert
Licensed User
Longtime User
Here you are.
Attached a new project.
It did take some time, I had to learn how the B4XDrawer works, I had never used it, and I made a new project from scratch.
This is a B4XPages project with the advised structure, I do not use your mdlPageX modules only B4XPageX modules.
The hamburger.png file is in the SharedFiles folder.
Tested with all three platforms. It works in B4J and B4A.
Unfortunately, it does not work with B4i, I get an error when calling: B4XPages.ShowPageAndRemovePreviousPages("Page2")
I don't know what the problem is.

Copying updated assets files (8)
Application_Start
Application_Active
Error occurred on line: 370 (B4XPagesManager)
Expected: UIView, object type: b4i_b4xpage4
Stack Trace: (
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 1155368
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 119500
B4XPageAndDrawers -[B4IObjectWrapper setObject:] + 276
B4XPageAndDrawers -[B4XViewWrapper setObject:] + 152
B4XPageAndDrawers +[B4IObjectWrapper createWrapper:eek:bject:] + 108
B4XPageAndDrawers -[b4i_b4xpage4 _b4xpage_created::] + 876
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 1173616
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 8144
B4XPageAndDrawers +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
B4XPageAndDrawers -[B4ICommon CallSubDebug4::::] + 1080
B4XPageAndDrawers -[B4ICommon CallSubDebug2::::] + 372
B4XPageAndDrawers -[b4i_b4xpagesmanager _createpageifneeded::] + 1192
B4XPageAndDrawers -[b4i_b4xpagesmanager _showpageandremovepreviouspages::] + 960
B4XPageAndDrawers -[b4i_b4xpages _showpageandremovepreviouspages:] + 568
B4XPageAndDrawers -[b4i_b4xmainpage _btnpage4_click:] + 560
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 1173616
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 8144
B4XPageAndDrawers +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
B4XPageAndDrawers -[B4IShell runMethod:] + 448
B4XPageAndDrawers -[B4IShell raiseEventImpl:method:args::] + 2172
B4XPageAndDrawers -[B4IShellBI raiseEvent:event:params:] + 1580
B4XPageAndDrawers __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib A564FA91-A3E3-3A41-AFD1-410FAD72E52A + 393880
libdispatch.dylib A564FA91-A3E3-3A41-AFD1-410FAD72E52A + 397952
libdispatch.dylib A564FA91-A3E3-3A41-AFD1-410FAD72E52A + 66108
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 629808
CoreFoundation F80FCA31-BF76-3293-8BC6-1729588AE8B6 + 606440
CoreFoundation CFRunLoopRunSpecific + 572
GraphicsServices GSEventRunModal + 160
UIKitCore 00EA1426-38F7-3FD2-BE01-04EBD44ECA35 + 11669508
UIKitCore UIApplicationMain + 164
B4XPageAndDrawers main + 124
libdyld.dylib 77E57314-8A58-3064-90C0-8AF9A4745430 + 5528
)
 

Attachments

  • B4XPageAndDrawers.zip
    151.7 KB · Views: 170

klaus

Expert
Licensed User
Longtime User
Maybe I'm lost but... are you sure Klaus?
Yes, I am sure.
In Elrics' project in post #1 he uses for each Page:
a B4XPageX.bas and a mdlPageX.bas module, for each page he uses two modules.

1610654014580.png

I use only P4XPageX modules.
1610654084714.png
 
Top