Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #9504 > unrolled thread

IsMethod() for use in functions

Started byD.J.W. van Kooten <vankooten@removethis.ic2.com>
First post2016-07-05 19:01 +0200
Last post2016-07-07 08:18 +0200
Articles 9 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  IsMethod() for use in functions D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2016-07-05 19:01 +0200
    Re: IsMethod() for use in functions "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-07-05 20:06 +0200
      Re: IsMethod() for use in functions D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2016-07-05 21:11 +0200
        Re: IsMethod() for use in functions "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-07-06 08:26 +0200
    Re: IsMethod() for use in functions "Karl-Heinz" <invalid@invalid.invalid> - 2016-07-05 21:19 +0200
      Re: IsMethod() for use in functions D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2016-07-06 12:00 +0200
        Re: IsMethod() for use in functions "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-07-06 14:55 +0200
        Re: IsMethod() for use in functions "Karl-Heinz" <invalid@invalid.invalid> - 2016-07-06 21:05 +0200
        Re: IsMethod() for use in functions "Karl-Heinz" <invalid@invalid.invalid> - 2016-07-07 08:18 +0200

#9504 — IsMethod() for use in functions

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2016-07-05 19:01 +0200
SubjectIsMethod() for use in functions
Message-ID<aopnnb109gjouifhggg7qntmlhv2aca0ri@4ax.com>
I use IsMethod() from time to time. E.g. If 

IF IsMethod (SELF, #OnlyForSomeUsers)
	Send (SELF, #OnlyForSomeUserl)
ENDIF

It allows me to write a method OnlyForSomeUser of the same class which
is only present in one specific main program which includes the
library with the above code. I can easily extend some general
functionality for just one specific client's version without a whole
subclassing job, by calling that method OnlyForSomeUser via Send.

Can I do something similair from within a function? I vaguely remember
there was something like that.

Dick

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

[toc] | [next] | [standalone]


#9505

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2016-07-05 20:06 +0200
Message-ID<du2b9sF4tbaU1@mid.individual.net>
In reply to#9504
Hi Dick,

> I use IsMethod() from time to time. E.g. If 
> 
> IF IsMethod (SELF, #OnlyForSomeUsers)
> 	Send (SELF, #OnlyForSomeUserl)
> ENDIF
> 
> It allows me to write a method OnlyForSomeUser of the same class which
> is only present in one specific main program which includes the
> library with the above code. I can easily extend some general
> functionality for just one specific client's version without a whole
> subclassing job, by calling that method OnlyForSomeUser via Send.
> 
> Can I do something similair from within a function? I vaguely remember
> there was something like that.

I don't know if there is a function to check for a function existence -
but you can call a function with Clipper calling convention with
_CallClipFunc() passing the parameters in an array.

Wolfgang

-- 

[toc] | [prev] | [next] | [standalone]


#9506

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2016-07-05 21:11 +0200
Message-ID<7b1onb5ll4canvl4atovj95868k9knr8d9@4ax.com>
In reply to#9505
Replying on message of Tue, 5 Jul 2016 20:06:51 +0200 from Wolfgang
Riedmann:


 Hello Wolfgang,

>I don't know if there is a function to check for a function existence -
>but you can call a function with Clipper calling convention with
>_CallClipFunc() passing the parameters in an array.
>

I wasn't aware of this one (I even couldn't find it in the help! -
where did you get this from?) I see that it's used in the
SystemLibrary a few times.

But somehow it doesn't seem to work. I have this in my code:

_CallClipFunc(#TestThis,{"Hello"})

and straight below it:

FUNCTION TestThis(cParm AS STRING)
ErrorBox{,cParm}:Show()
RETURN TRUE

But TestThis isn't called, I see when I pass _CallClipFunc using the
debugger. 

Any idea why not?

Dick

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

[toc] | [prev] | [next] | [standalone]


#9510

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2016-07-06 08:26 +0200
Message-ID<du3mk6FegtbU1@mid.individual.net>
In reply to#9506
Hi Dick,

> > I don't know if there is a function to check for a function
> > existence - but you can call a function with Clipper calling
> > convention with _CallClipFunc() passing the parameters in an array.
> > 
> 
> I wasn't aware of this one (I even couldn't find it in the help! -
> where did you get this from?) I see that it's used in the
> SystemLibrary a few times.

it is not documented <g>. I think someone pointed me there...

> But somehow it doesn't seem to work. I have this in my code:
 
> _CallClipFunc(#TestThis,{"Hello"})
> 
> and straight below it:
> 
> FUNCTION TestThis(cParm AS STRING)
> ErrorBox{,cParm}:Show()
> RETURN TRUE

maybe you should remove the "as string" from the parameter?

For me the following code works:

METHOD OKButton( ) CLASS MainDialog

_CallClipFunc( #DickFunc, { self, "Hi Dick" } )

SELF:EndDialog(0)
RETURN SELF	

function DickFunc( oWindow, cMessage )

InfoBox{ oWindow, "DickFunc", cMessage }:Show()
	
return nil

Wolfgang

-- 

[toc] | [prev] | [next] | [standalone]


#9507

From"Karl-Heinz" <invalid@invalid.invalid>
Date2016-07-05 21:19 +0200
Message-ID<du2fsnF62hoU2@mid.individual.net>
In reply to#9504
Hi Dick,

>IF IsMethod (SELF, #OnlyForSomeUsers)
>Send (SELF, #OnlyForSomeUserl)
>ENDIF
>
>Can I do something similair from within a function? I vaguely remember
>there was something like that.

As Wolfgang mentioned you can use  _CallClipFunc(), but there´s also a
function named  _CallClipFuncPtr().

e.g.

IF (hFunc :=  FunctionSym2Ptr ( #Test )) != NULL_PTR
    _CallClipFuncPtr ( hFunc , { 12 , 16 , "First" }  )

ENDIF

or a more generic solution:

IF IsClipperFunction ( #Test )
    CallClipperFunction ( #Test , { 1 , 8 , "second" } )

ENDIF


----------------------
FUNCTION CallClipperFunction ( symFunc AS SYMBOL , aArgs AS ARRAY ) AS USUAL
PASCAL

    RETURN _CallClipFunc ( symFunc , aArgs )
-----------------------------------------
FUNCTION IsClipperFunction ( symFunc AS SYMBOL )AS LOGIC PASCAL

    RETURN  FunctionSym2Ptr ( symFunc ) != NULL_PTR
-------------------------
FUNCTION Test ( n1  , n2  , c  ) AS STRING  _NC CLIPPER

    MessageBox ( NULL , String2Psz ( NTrim ( n1 + n2 ) + crlf + c ) ,NULL ,
0 )


    RETURN  "Returnvalue"

----------------------------------------


Regards
Karl-Heinz 

[toc] | [prev] | [next] | [standalone]


#9512

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2016-07-06 12:00 +0200
Message-ID<dvkpnbtaoduc0jdg09kfc60v3hdur1ivia@4ax.com>
In reply to#9507
Replying on message of Tue, 5 Jul 2016 21:19:42 +0200 from Karl-Heinz:


 Hello Karl-Heinz, Wolfgang,

This is weird...

I first changed my paramaters as in Wolfgangs sample - the first being
oWindow. There's no self in a function but I passed nil - and it
worked! Tried it twice.

Then I moved the called function to another (included) AEF. Nothing. I
moved it to the same AEF as where it was called from. Nothing. I moved
it back to the same mef. Again nothing while it worked 5 minutes ago.
Also nothing after a reindex. I put a button calling OkButton somehere
on a window so I could use the code of Wolfgang exactly. Nothing.

Then I tried the code of Karl-Heinz which seems exactly what I am
looking for. And again, nothing. Even
lNew:=IsClipperFunction(#Whateverexistingfunction) returns false
(null_ptr everytime). Whatever function name I choose, including the
function from where it is called...

I wonder what causes this to fail -maybe a compiler setting or
something- but then I even wonder more what caused it to work just
twice. 

Without any documentation (I checked the help file, internet, the old
turned-yellow printed manuals and even the System SDK -where there is
no source, only _DLL FUNCTION FunctionSym2Ptr(symFunc AS SYMBOL) AS
PTR     PASCAL:VO28RUN.FunctionSym2Ptr- I think it's hard to find out.
It's probably not a good idea to rely on undocumented functions?

Dick

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

[toc] | [prev] | [next] | [standalone]


#9513

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2016-07-06 14:55 +0200
Message-ID<du4ddjFjtmkU1@mid.individual.net>
In reply to#9512
Hi Dick,

I use this function very often, and it works everytime.

But: 

> Then I moved the called function to another (included) AEF. 

if you don't reference the function anywhere it is simply not present
in the exe - not linked in....

Try to use a request myfunction anywhere in the library or exe, then it
should be linked in.

But for customer dependent functionality I would use a completely
different approach: put your functionality in a method of a class. Then
you can load the DLL with the required functionality at runtime,
instantiate the object with CreateInstance() and execute the method
with Send().

When loading a VO DLL, you need to execute a function after the
loadlibrary() call to make the runtime load the classes and methods in
the DLL.

This is how I load such DLLs:

function LoadCPPlusDLL( oWindow as Window ) as logic pascal
local lRetCode		as logic
local hDLL			as ptr
local hProc			as ptr
local cDLLName		as string
local cVOVersion	as string

if IsClass( #ZipClass )
  lRetCode		:= true
else
  cDLLName			:= "CPPlus28.DLL"
  hDLL			:= _VOLoadLibrary( cDLLName )
  if hDLL == null_PTR
    ErrBox( oWindow, "error loading the DLL" )
    return false
  else
    hProc := GetProcAddress( hDLL, String2Psz( "CPPlusInitDLL" ) )
    if hProc == null_ptr
      ErrBox( oWindow, "error initializing" )
      return false
    endif
    PCall( hProc )

    if IsClass( #ZipClass )
      lRetCode		:= true
    else
      ErrBox( oWindow, "error initializing" )
      return false
    endif
  endif
endif

return lRetCode

Wolfgang


-- 

[toc] | [prev] | [next] | [standalone]


#9515

From"Karl-Heinz" <invalid@invalid.invalid>
Date2016-07-06 21:05 +0200
Message-ID<du5343Fp9q7U1@mid.individual.net>
In reply to#9512
Hi Dick,

>
> Also nothing after a reindex
>

after a reindex i always "touch" and "recompile"

>
> Then I moved the called function to another (included) AEF
>

when you move the  function  to a LIB, add a external statement to your exe
start()

e.g. making my  earlier posted "Test" Function visible:

EXTERNAL Test


Regards
Karl-Heinz

[toc] | [prev] | [next] | [standalone]


#9516

From"Karl-Heinz" <invalid@invalid.invalid>
Date2016-07-07 08:18 +0200
Message-ID<du6ajfF3c46U1@mid.individual.net>
In reply to#9512
Hi Dick,

in addition ...

> Without any documentation (I checked the help file, internet, the old
> turned-yellow printed manuals and even the System SDK -where there is
> no source, only _DLL FUNCTION FunctionSym2Ptr(symFunc AS SYMBOL) AS
> PTR     PASCAL:VO28RUN.FunctionSym2Ptr- I think it's hard to find out.
> It's probably not a good idea to rely on undocumented functions?

Rod published ages ago such internals in the SDT/XBase magazines, and they
are still alive. I´m not aware of that there are any future plans for a
completely redesigned "VO 3.0 to the max" ;-)

On the other side: Why not create a DLL with strongly typed Functions only
and handle the content dynamically using Loadlibrary(), GetProcaddress() and
PCall() ?


Regards
Karl-Heinz 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web