Read while runtime all Form name in a project

Post

Posted
Rating:
#1 (In Topic #1390)
Trainee
 Good afternoon

Is there any way to get a list of all the forms in the project at runtime, not just the active ones but all of them?

thanks
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Try this: -

Code (gambas)

  1. Public Sub ListForms()
  2.  
  3.   Dim sForms As String[] = Dir(Application.Path &/ ".src", "*.form", gb.File)
  4.  
  5.   For iLoop As Integer = 0 To sForms.Max
  6.     Print sForms[iLoop]
  7.   Next
  8.  
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Trainee
thank you for your solution.
while I was waiting for an answer I found the same solution as you,
but this only works on IDE and therefore the result must be stored on disk (for example in the .hidden directory) or on a database to then be used after installing the deb file on another machine

Code

  
  Dim s As String
  #If Not (Exec)   
      var.listModules = New String[]
      For Each s In Dir("./.src", "*.form").Sort()
        var.listModules.Add(File.basename(s))
      Next
      File.Save(Application.path &/ ".hidden/modlist.txt", JSON.Encode(var.listModules))
  #Endif
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Nothing in the .hidden directory gets put into the archive. the .hidden folder is only for the IDE usage.
In fact ALL hidden folders and hidden files are excluded from the executable except a folder called .public that we can use and the .gambas/ folder where the compiled binaries live.

You can see what is in an executable using gba3 -l
eg.
$ gba3 -l /path/to/project/project.gambas

The "#If Not (Exec)" is what makes it only work on the IDE (i assume you knew that)
When the IDE makes the executable archive it sets the exec flag.
#If Not (Exec) is true if run from the IDE or if you run the project not the archive (eg, gbx3 /path/to/project-folder)

But note:
Once in an archive the .src folder is only accessible if the executable archive remains in the project folder.

I do not know how the packager works but if it is like the Farm downloads/installs then the executable goes in ~/.local/gambas3/bin/ and the project goes in ~/.local/gambas3/src/

in which case once installed the files in ./.src are no longer visible to the executable.

Also you are calling these Forms Modules?
Will that not confuse things as in gambas there are .class, .form and .module files.
Online now: No Back to the top

Post

Posted
Rating:
#5
Trainee
Hi BruceSteers, thank you for your reply.

I would like to clarify some things because I have not been able to explain well what my request for help was for.
My project either runs on IDE, so during programming and testing, or it runs on cloud on remote machines, for this it needs an .deb installation package, on Xrdp server with VPN connection.
The .hidden folder, as you say, and as reported in the wiki:

[.hidden] Directory that includes all project files that must not go inside the executable. This is the "Project" folder in the IDE project tree view. It can contain sub-folders.

And it is true that the files are not inserted in the .DEB installation package but when you do setup to generate an installation file in section 8 it asks if you want to insert extra files and these extra files must be in the project directory and among these .hidden as suggested by the author of the IDE.

My project has about a hundred files between forms, classes and modules. The modules (listmodules) I was referring to in my post are "software modules", so the standard definition given to a software that can run autonomously. In my case the software module corresponds in most cases to a Form, and my request to obtain a list of Forms is used to have an updated list that the software superuser must use in order to decide which "software module" will be available or not for the specific end user.

#If Not (Exec) is used to run the code only in the IDE, because in my case the software runs on an IDE or on a remote machine where it is installed via the DEB package and therefore without sources. So if you don't use the #if Not (Exec) the binary executable obviously won't find any .src directory and would go into error. Of course there are other methods to implement the same function.

Thank you for the solution using gba3 whose -l option I didn't know and I think I'll use this solution including gba3 among the gambas runtime packages to install
Online now: No Back to the top
1 guest and 0 members have just viewed this.