Is there some reason that I can't release a form from within its load event? I have identified a situation in which I want to do that but the release() doesn't seem to do anything.
There has to be some purpose in calling a form. The forms objects will get initialised only after the load events.
You could call some contained objects methods, after their respective inits. So doing such initialisation and then calling some events, and then checking if some values are this way or that way, then based on those results you will be calling to release the form or continue it. That is the reason, I suggested to return .f. from init event.
If the only purpose is to run the code in load of a form, then, better that code can be run from a procedure or function. So even if Load will return .f. and technically
will release the form, I did not suggest that.
The form in question displays the contents of a purchase order. The Load event checks to see if the PO is new, i.e., whether to create it. (PO# = 0 => create) The Load event calls Procedure NewPO if needed to create a record in the PO table, changing the PO# to > 0. Then the Load event opens the PO table to the correct PO, new or not.
Under some extremely rare circumstances, NewPO may not be able to create a PO at the time. The new PO# is assigned by finding the biggest PO# currently in the table, locking that record, adding one to the PO#, inserting the new record, and unlocking the locked record. If another user tries to create another PO at the precisely correct moment, their attempt to lock will fail. (Maybe it's the precisely wrong moment? <g>) In that case, the PO# still = 0 so I display a message to the user, and do not open the PO form. The circumstances are obscure and have happened only twice in seven years that I'm aware of. (Over 50,000 POs have been created on this system during that time.)
It is true that I could create a procedure that does NewPO and OpenPO and then does form PurchaseOrder. But before I saw the need for this I wrote the code in the Load event. In the spirit of "don't mess with it more than you need to" I just wanted to modify the Load event.
If the only purpose is to run the code in load of a form, then, better that code can be run from a procedure or function. So even if Load will return .f. and technically
will release the form, I did not suggest that.
I can think of other reasons to return .F. from the Load. <g> A case I've had recently was for a Tool Inventory system. You have to define tools in the Tool Master screen to set things up. The Transfers screen will check if you have have anything in the ToolMaster table. If not, I display a MESSAGEBOX that you need to setup tools first and then I just return .F. from the Load.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.