[Gambas-user] Form open - simple question
Bruce
bbruen at ...2308...
Sat Apr 20 11:44:07 CEST 2013
On Sat, 2013-04-20 at 02:14 -0700, bill-lancaster wrote:
> I want to open a form and immediatly display the progress of a process.
>
> If I do it in the form_open event the form isn't displayed untill the
> process is complete.
>
> I can't find an event for the form that will do this simple thing!
>
> Any ideas?
Bill,
I use "pop-up" progress bar forms very frequently, as I am usually
working with hundreds of text files that need to be loaded, parsed and
have objects created accordingly.
Typically I use a module to do the actual load/parse/instantiate and a
"progress" form with a ProgressBar to show how far we have got, so far.
I believe that the "trick" that you are looking for is the WAIT command.
Here's some code from a hack project that uses this approach, hope you
can decipher it. I have chucked some !!! notes in to help.
cheers
Bruce
Private Sub LoadPAKSet()
Dim sDir As String
Dim aPaths As New String[]
Dim sObjPath As String
Dim hDATFile As DATFile
Dim aSource As String[]
Dim wkObj As DATObject
Dim iObjTotal As Integer
Dim idx As Integer
Dim aLog As New String[]
Dim fProg As FLoadProgress
Dim iObjCount As Integer
Dim iObjNull As Integer
sDir = $PAKDir
LoadDirTree(sDir, aPaths)
iObjTotal = aPaths.Max
idx = 0
fProg = New FLoadProgress(iObjTotal) !!! START HERE
fProg.Show !!! OPEN THE PROG BAR FORM
For Each sObjPath In aPaths
Inc idx
Application.WriteLog("Reading " & sObjPath)
' SPECIAL CASES
If sObjPath Ends "pak128-program_texts.dat" Then Continue '
Ign
hDATFile = New DATFile
hDATFile.LoadFile(sObjPath)
For Each aSource In hDATFile.SourceObjects
Application.WriteLog("Loading " & aSource[0])
wkObj = DATGenericBuilder.Create(aSource, sObjPath)
If wkObj Then
aLog.Add(Subst("[&1/&2 (&3%) Loaded :&4", idx,
iObjTotal, Round(idx / iObjTotal * 100, 0), wkObj.Name))
If Not wkObj.Key Then
Application.WriteLog("ERR (Level 0) Object parser
incomplete for " & hDATFile.SourcePath)
Stop
Endif
$PAKset.Add(wkObj, wkObj.Key)
Inc iObjCount
Else
Inc iObjNull
Endif
Next
fProg.Loaded = idx !!! HERE WE UPDATE THE PROGRESS BAR
Next
fProg.Close !!! FINISHED WITH THE PROG BAR FORM
Print Subst("&1 individual objects loaded, &2 nulls returned",
iObjCount, iObjNull)
LoadTreeView
Catch
Error Subst("&1\nERR: &2 (&3)\n&4\n&1\n", String$(40, "-"),
Error.Text, Error.Code, Error.Backtrace.Join("\n"))
Stop
End
And the FLoadProgress class looks like this (the form has a textbox (?
maybe a textlabel? I can't remember) and a progress bar.
' Gambas class file
''
'=================================================================
'==== EVENT Declarations
====
'=================================================================
'=================================================================
'==== Property Declarations
====
'=================================================================
Property Loaded As Integer
'=================================================================
'==== Local Property Variables
====
'=================================================================
'=================================================================
'==== Local Variables
====
'=================================================================
Private $TotalToLoad As Integer
'=================================================================
'==== Special Methods
====
'=================================================================
Public Sub _new(TotCount As Integer)
'' Constructor
$TotalToLoad = TotCount
Label1.Text = Subst(Label1.Text, $TotalToLoad)
End
'=================================================================
'==== Public Methods
====
'=================================================================
'=================================================================
'==== Private Methods
====
'=================================================================
'=================================================================
'==== Property Accessors
====
'=================================================================
'=================================================================
'==== Event Handlers
====
'=================================================================
Public Sub Form_Open()
Settings.Read(Me)
pbarLoad.Value = 0
End
Public Sub Form_Close()
Settings.Write(Me)
End
Private Function Loaded_Read() As Integer
Return -1
End
Private Sub Loaded_Write(Value As Integer)
pbarLoad.Value = Value / $TotalToLoad
Wait
End
Hope that helps and doesn't confuse. (I am too busy to distill a
succinct reply.
More information about the User
mailing list