Procedure pointers

S

stebain

Is it possible to pass a pointer to a function or procedure as a parameter
to a procedure?

[ie, I have a routine that would write out a stylized box, but then I want
it to be populated by a procedure dependant on which report version the user
wants]
 
K

Karl E. Peterson

stebain said:
Is it possible to pass a pointer to a function or procedure as a
parameter to a procedure?

[ie, I have a routine that would write out a stylized box, but then I
want it to be populated by a procedure dependant on which report
version the user wants]

There are ways to emulate this which are easy, and there are ways to
actually achieve this which can be mildly mind-boggling if you're not "an
object-oriented sorta guy."

The easiest way would be to enumerate your reports, pass an index value to
the procedure, then act on that in a Select Case block. If that won't do,
for some reason, I'd be happy to get into the more arcane methods.
 
S

stebain

Karl E. Peterson said:
stebain said:
Is it possible to pass a pointer to a function or procedure as a
parameter to a procedure?

[ie, I have a routine that would write out a stylized box, but then I
want it to be populated by a procedure dependant on which report
version the user wants]

There are ways to emulate this which are easy, and there are ways to
actually achieve this which can be mildly mind-boggling if you're not "an
object-oriented sorta guy."

The easiest way would be to enumerate your reports, pass an index value to
the procedure, then act on that in a Select Case block. If that won't do,
for some reason, I'd be happy to get into the more arcane methods.

I come from a pascal background, I'd be happy to hear the more arcane / oops
stuff!
 
K

Karl E. Peterson

stebain said:
Karl E. Peterson said:
stebain said:
Is it possible to pass a pointer to a function or procedure as a
parameter to a procedure?

[ie, I have a routine that would write out a stylized box, but then
I want it to be populated by a procedure dependant on which report
version the user wants]

There are ways to emulate this which are easy, and there are ways to
actually achieve this which can be mildly mind-boggling if you're
not "an object-oriented sorta guy."

The easiest way would be to enumerate your reports, pass an index
value to the procedure, then act on that in a Select Case block. If
that won't do, for some reason, I'd be happy to get into the more
arcane methods.

I come from a pascal background, I'd be happy to hear the more arcane
/ oops stuff!

Wow, this is the second time in the last month the same thing has come up,
both from a pascal/delphi perspective. <g>

One way we kicked around recently was to have class modules implement a
common interface, "IWhatever", that exposes some common method(s). You can
store a pointer to this interface, and reconstitute as needed with something
like this:

Private Function ResolvePointer(ByVal lpObj As Long) As IWhatever
Dim obj As IWhatever
' This function takes a dumb numeric pointer and turns it into
' a valid object reference.
' http://www.mvps.org/vbvision/collection_events.htm
CopyMemory obj, lpObj, 4&
Set ResolvePointer = obj
CopyMemory obj, Nothing, 4&
End Function

Does that make any sense?
 
S

stebain

I've never implented an interface in VBA/VB. Certainly something new to try
and kick around.

Thanks for the lead in, Karl.

-Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top