lun. 29 avril 2013, 13h03
Cesar Ch
Brésil
atoutfox.public.association
Re: Cesar CHALOM : GradBackground. DeclareAPI.
Jean,
Gradobjects is a really old class.
I would really make many things different it I wasdealing with it today.
For the API declarations, our friends are recommending the correct aproach, by declaring the API calls only once.
To make it work in a good way, we would need to create a separate PRG, where we would store al the API declarations using the "ALIASED" approach, like below, using the example provided by Greg:
If you have:
DECLARE LONG HeapAlloc in Kernel32.dll LONG, LONG, LONG
You can transform it in a Function
FUNCTION grdHeapAlloc(tnValue1, tnValue2, tnValue3)
DECLARE LONG HeapAlloc in Kernel32.dll AS grdHeapAlloc LONG, LONG, LONG
RETURN grdHeapAlloc(tnValue1, tnValue2, tnValue3)
ENDFUNC
This way, you can convert all the API calls and store them as separate PRGs or put them all in a PROCEDURE PRG. Notice hat using that aproach, you will need to call the new function "grdHeapAlloc" instead of "HeapAlloc", understand?
This is very cool, because in a first moment, VFP will look if there is an API declared. If it does not find it, then it will look at the procedures. In my opinion, this is the safest way to deal with API calls. Even if there is a CLEAR DLLS command somewhere, these functions will still work normally !!!
Another good reason for using "Aliased" API calls is that some API functions allow us to use them in several ways, sometimes passing INTEGERS, other times STRINGS to the parameter. But in VFP we always need to declare exactly the types that the function is expecting. This way, you can Declare the same API function several times, with different parameter types, and work normally.
So, for your case, for GradObjects, my recomendadtion is the following:
- Remove all the API declarations and store them in a separate PRG
- In that PRG, make all API calls as "Aliased", putting the prefix "grd" or any other that you like
- Modify all the API calls in Gradobjects source, and add the new "grd" prefix. I'ts easy to find those functions, all of them start with "Gdip"
- At the GradObjects initialization, add a code similar to the below:
IF NOT "GradObjectsAPI" $ SET(PROCEDURE)
SET PROCEDURE TO "GradObjectsAPI" ADDITIVE
ENDIF
Capiche, mon ami ?
Salutations
Cesar
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000011869