EinTerraner
Technical User
Last edited:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
PROCEDURE INIT
IF NOT FILE("INVOICE.DBF")
ERROR 'Initialization Failed: File not found'
RETURN .F.
ELSE
USE INVOICE IN 0 AGAIN
THIS.WorkArea = SELECT()
ENDIF
ENDPROC
Yepp, this I know, but i could not yet figure out how to pass a failed init-method (return .f.) (done workaround see below)If you want stop form to continue loading, then you must put RETURN .F. to form's Init() or form's Load().
well with an cascaded FOREACH Obj in Form.obects i can check the exitence of an object and/or their sub-objects. But in can't find any unloaded objects. Where i can see what objects where added in the form by using the form-designer. In the LOAD-method i dnt see yet anythingAnyway, you could verify the existance of all form controls in form init and then choose to quit the form.
not only in the form.init. But also in some objects that I glue into the form.Do you have any program code in the form's Init event?
&& MyForm has a property named "DontRunForm"
&& already declared in the form-classlib
&& This is the basic-init-method in my form-classlib
LPARAMETERS Parm1, Parm2
IF VARTYPE(This.DontRunForm) == "C"
=MESSGEBOX(This.DontRunForm, 16, "Can't show Window ["+This.Name+"]", 10000)
ENDIF
&& Initialize basic form requirement
RETURN EMPTY(This.DontRunForm)
&& This is the init-method in my used form (designer)
IF !DODEFAULT(Parm1, Parm2)
RETURN .f.
ENDIF
&& This is the init-method in any used objects-classes or used in the form
LPARAMETERS Parm1, Parm2
&& Initialize this Object if required
IF AnyThingFails
ThisForm.DontRunForm = "Error description"
ENDIF
RETURN
...is that you would know what objects you expect. You could only check that in Init(), in Load() nothing is yet initialized. And you can only check so with knowledge of what structure you expect to exist.Anyway, you could verify the existance of all form controls in form init
Public oform1
oform1=Newobject("form1")
If Vartype(oForm1) = "O"
oform1.Show
EndIf
Return
*
Define Class form1 As Form
DoCreate = .T.
Caption = "Form1"
lload = .F.
Name = "Form1"
Add Object command1 As myCommand With ;
Top = 24, ;
Left = 12, ;
Height = 27, ;
Width = 84, ;
Caption = "Command1", ;
Name = "Command1"
Procedure Init
Return Thisform.lload
Endproc
Enddefine
Define Class myCommand As CommandButton
Procedure Init
*!* Changing the value of a custom property prevents the form Init
Thisform.lload = .T.
Endproc
Enddefine
Like in an old thread (2005 or like) i've read before i started this one inside any object./form.init-method it does not work to insert something like ThisForm.Release()AFAIR form.init runs after objects.init. Maybe you can have a form property lProblem which you set to .t. in .init of controls before return .f.
Then in form.init or whatever you can kill the form if its set to .t. by one or more controls
not to protect my form and neither my exe-file.I still don't see the use case.
LPARAMETERS p1,p2
Local llContinue
* This form subclass considerations to run or quit
* setting llContinue to .F. or .T.
RETURN DODEFAULT(p1,p2) AND llContinue
1st) all forms have the same init-behavior and thei own init-procedere where i do initialize formspecific properties.And you should consider letting all controls involved adding reasons to the DontRunForm property, not overwrite it
LPARAMETERS P1, P2, P3, P4, P5, P6
WITH This
IF .UseStatusBar
SET CLASSLIB TO (.F_BALLOON.ClassLibrary) ADDITIVE
.AddObject( "F_StatBar", "ctl32_StatusBar")
ENDIF
.Form_HideTime_Count = .Form_HideTime_Value
.Par1 = P1
.Par2 = P2
.Par3 = P3
.Par4 = P4
.Par5 = P5
.Par6 = P6
BINDEVENT(.F_SYSTICK,"SecTimer",This,"TimerEvent")
BINDEVENT(.HWnd, WM_POWERBROADCAST, This , "Form_WinMsgs", 4)
IF VARTYPE(.DoNotLoad) == "C" ;
.and. !EMPTY(.DoNotLoad)
=MESSAGEBOX(.DoNotLoad, 16, "Fenster ["+.Comment+"] nicht verfügbar", 10000)
ENDIF
IF !EMPTY(.DoNotLoad)
RETURN .f.
ENDIF
&& here follows the rest of the INIT
&& MyObject.INIT
LOCAL Lc_Reor
IF TYPE("ThisForm") == "O" ;
.and. !EMPTY(ThisForm.DoNotLoad)
RETURN .f.
ENDIF
&& do my init here...
&& here the part, where any error might happen
IF .SrvExist
.UseSrvFile(.SrvAlias)
Lc_Reor = !.Data_Test(.SrvAlias)
USE IN SELECT(.SrvAlias)
ENDIF
IF !Lc_Reor ;
.and. .LocExist
.UseLocFile(.SrvAlias)
Lc_Reor = !.Data_Test(.SrvAlias)
USE IN SELECT(.SrvAlias)
ENDIF
IF Lc_Reor && error present
IF MESSAGEBOX("File for ["+.Comment+"] needs to be updated.", 16+4, "System update required", 10000) == 6 && JA
.Data_Reorg()
ELSE
IF TYPE("ThisForm") == "O"
ThisForm.DoNotLoad = "Reorganisieren von "+.Comment+" verweigert"
ENDIF
RETURN
ENDIF
ENDIF
WITH THIS
...
IF VARTYPE(.DoNotLoad) == "C" ;
.and. !EMPTY(.DoNotLoad)
=MESSAGEBOX(.DoNotLoad, 16, "Fenster ["+.Comment+"] nicht verfügbar", 10000)
ENDIF
IF !EMPTY(.DoNotLoad)
RETURN .f.
ENDIF
...
ENDWITH
WITH THIS
...
IF !EMPTY(.DoNotLoad)
=MESSAGEBOX(.DoNotLoad, 16, "Fenster ["+.Comment+"] nicht verfügbar", 10000)
RETURN .F.
ENDIF
...
ENDWITH
All other following objects where this case might occur have following code as the first statement in the init method.
IF TYPE("ThisForm") == "O" ;
.and. !EMPTY(ThisForm.DoNotLoad)
RETURN .f.
ENDIF
IF !EMPTY(ThisForm.DoNotLoad)
RETURN .f.
ENDIF
I see, It seems an unelegant solution to me, but I can't think of a general more elegant way from the top of my hat.Therefore the TYPE("ThisForm") up there.
TRY
IF !EMPTY(ThisForm.DoNotLoad)
RETURN .f.
ENDIF
CATCH
ENDTRY
Localk loIO
loIO = CreateObject("yourioclass") && which has RETURN .F. in init, if requirements are not met
IF ISNULL(loIO)
Return .f.
ENDIF
*...continue with loading....
i agreeAnd, yes, that's also not more elegant, I agre
But in this case it needs some kind of coding within the form.load and/or form.init. And i have this class with different properties/functions up to 10 times within one form.Instead of just puttin the object on the form.
DODEFAULT() && unbind and sum more
with This && Grid-PostInit
set order to (ThisForm.SlaveGrid.RelOrder) in (ThisForm.SlaveGrid.RelAlias)
select(.DisAlias) && it's a cursor, not the real table
set relation to (.RelOrder) into (ThisForm.SlaveGrid.RelAlias) ADDITIVE
endwith