Internal procedure already defined

-Zigo-

Member
Is it possible to tell programatically if an internal procedure has already been defined?

Our systems use many include files, some of which contain external procedure references like user32. Within a different include file I need to use the GetParent external procedure of user32, so I need to know whether this has already been defined.

(these may not be the best methods for programming, I know, but the core parts of our systems have been set in stone since...well...the stone age, and no-one is going to rewrite it all now)
 

bulklodd

Member
Could you explain more explicitly what you mean by "to tell programatically if an internal procedure has already been defined"? It's obvious, isn't it? You need just to compile it to detect that. Why isn't this way suitable for that?
 

joey.jeremiah

ProgressTalk Moderator
Staff member
you can mark the include file has already been used at compile-time. heres a rough winapi include example.

Code:
/* start-super.i */

{1} = session:first-procedure.

do while valid-handle( {1} ) and {1}:file-name ne {2}:
    {1} = {1}:next-sibling.
end.

if not valid-handle( {1} ) then
run {2} persistent set {1}.

&if "{3}" = "" &then
      session:add-super-procedure( {1} ).
&else {3}    :add-super-procedure( {1} ).
&endif



/* winapi.i */

&if defined( WinAPI ) = 0 &then

    define var phWinAPI as handle no-undo.
    {start-super.i phWinAPI "'winapi.p'"}

    &global WinAPI defined

&endif /* defined = 0 */



/* winapi.p */

procedure GetParent external "user32.dll":
    define input  param hWinHdl    as long.
    define return param hwndParent as long.
end procedure.

you could also use a prototype include, but there's something to be said about simplicity.
 

-Zigo-

Member
bulklodd said:
Could you explain more explicitly what you mean by "to tell programatically if an internal procedure has already been defined"? It's obvious, isn't it? You need just to compile it to detect that. Why isn't this way suitable for that?
By programatically I mean dynamically, when the program is being run. You're right in that I get compile errors if I have tried to define a procedure twice, but if you read what my aim was you'll see that I was trying to encapsulate everything within an all-purpose include file. Some places where I would use the include file already had the procedure defined, and some didn't - I just wondered if there was a simple way of bypassing the definition if it was known that it already exists.


Thanks joey, I see your suggested method would work nicely. As it is, I already found a solution, but if I need to change anything like this again I can refer to that.
 
Top