Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DoDefault() or Hooks?
Message
From
13/08/1999 09:14:52
 
 
To
13/08/1999 06:35:08
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00252400
Message ID:
00253363
Views:
20
John,

It has to do with control of flow - both within the method and external.

Internally, you probably don't want much of anything to run if the PreStuff() doesn't return .T.. In my previous example:

*-----------------------------------
local lbOK
lbOk = .F.

if PreHook()
lbOK = DoStuff()
= PostHook()
endif

return lbOK
*-----------------------------------

If PreHook doesn't return .T., then DoStuff() and POstHook() do not run and the whole method return .F. So what might be in "PreHook()? Usually some kind of "validation" that it is OK to run the rest of the method - may be something as simple as asking user for verification ... may be some check of data, etc. ... or could be some sort of set-up routine needed before running rest of the method.

Externally, you may want to kill or re-route the calling method if the whole thing doesn't return .T. - for example, if the method is an init method, returning .F. will prevent the object from initializing at all!

As for DoDefault(), depending on what you are doing, you may need to put it "inside" the PreStuiff or around the whole thing.

Ken

>Ken,
>
>Thanks for the reply. Is there any difference between your method and doing something like this in the method.
>
>MyForm.Init
>
>DO SomePreStuff()
>...
>DoDefault()
>DO SomePostStuff()
>...
>
>Thanks
>>John,
>>
>>As opposed to Sylvain's method, I do not like imbedded returns in most cases. I am of the school that methods/prgs/etc should have "one way in and one way out". with that in mind, I use something like:
>>
>>*-----------------------------------
>>local lbOK
>>lbOk = .F.
>>
>>if PreHook()
>> lbOK = DoStuff()
>> = PostHook()
>>endif
>>
>>return lbOK
>>*-----------------------------------
>>
>>If you need a DoDefault() or to die if the PostHook fails (I usually don't), that can be easily implemented.
>>
>>Ken
>>
>>
>>
>>>Ken,
>>>
>>>Thanks for some things to ponder about... BTW, how do you "Kill" the method if you return a .F.?
>>>
>>>Thanks
>>>
>>>>John,
>>>>
>>>>I have hooks everywhere in my framework. I love 'em. I do agree with Jim B. in that I ALWAYS do a DdDefault() whenever I write code in a VFP base method.
>>>>
>>>>The key to hooks is consistent naming and placement. for example - most of my pertinent methods/events have PreMethod and PostMethod hooks. PreMethod hooks can always "kill" the method/event if they return .F.. On occasion, I will also have specific named hooks for special needs. I always make sure to name them SomthingHook().
>>>>
>>>>Ken
Ken B. Matson
GCom2 Solutions
Previous
Reply
Map
View

Click here to load this message in the networking platform