IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Why yes of course; ever since Turbo Pascal AFAIK.
Just use the @ ("address-of") operator.

Now, (Object) Pascal being as type-safe as it is, this will of course be easiest if all your functions (or procedures) have the same "signature", i.e, number and types of parameters. If they do, it ought to be as simple as:

type
MyFunctionType: function(Param1: Integer; Param2: Real): Integer;
MyFunctionArray: array[1..3] of MyFunctionType;

procedure StuffEmInArray;
begin
MyFunctionArray[1] := @SomeFunctionOfMyType;
MyFunctionArray[2] := @AnotherFunctionOfMyType;
MyFunctionArray[3] := @TheseFunctionAreOfCourseDeclaredAlready;
end; { procedure StuffEmInArray }


If they have different signatures, you'll have to fiddle around with explicit type-casts to "defeat" (or "fool") the type-safety:

type
MyFunctionArray: array[1..3] of Pointer;

procedure StuffEmInArray;
begin
MyFunctionArray[1] := Pointer(@SomeFunctionOfAnyType);
MyFunctionArray[2] := Pointer(@SomeFunctionOfAnotherType);
MyFunctionArray[3] := Pointer(@TheseFunctionMustStillBePredeclared);
end; { procedure StuffEmInArray }


And then you have the problem that when you use these untyped pointers, you might have to cast them back to a specific function type -- preferably the right one for each... (I'm not sure if you can call code just like "MyResult := MyFunctionArray[Index](MyInteger, MyReal);", etc; maybe not with untyped function parameters.)



But I'm not sure you have to go this "low-level" at all -- it doesn't feel very "Delphi-style" to me. Have you investigated creating your own Event types (predefined "procedure(Param1: aType; Param2: aType ...) of Object" types of properties), and possibly dynamic event handler assignment? (Or, to be really naive, a case statement that branches to different functions/procedures depending on the tab-sheet's index -- or its Tag property; that's what it's for, after all -- in a common event handler?)

Anyway, this should all be pretty well documented in the Help files, so try looking for "function types" and the address-of operator, @.

HTH!



(NOTE: This is all from memory, so might contain syntax errors etc!)
   Christian R. Conrad
The Man Who Knows Fucking Everything
New Thanks....
....I'd gone on to changing what Events I was using so your solution was too late to use :) But I appreciate the tutorial on the address operator and making function types. It'll probably come in handy soon.
Jay O'Connor

"Going places unmapped
to do things unplanned
to people unsuspecting"
New Nuther question
[link|http://pub1.ezboard.com/fobjectorienteddevelopmentdelphi.showMessage?topicID=16.topic|Clearing a TListValueEditor]

Not sure if you'd prefer to field these here or there....
Jay O'Connor

"Going places unmapped
to do things unplanned
to people unsuspecting"
New Heh, that seems to have taken care of itself... :-)
New That was...ironically...
...the second case I had in one day of just plain bad programming.

Yesterday was not a good day of coding for me :)
Jay O'Connor

"Going places unmapped
to do things unplanned
to people unsuspecting"
     Function references in Delphi - (Fearless Freep) - (6)
         Why yes of course; ever since Turbo Pascal AFAIK. - (CRConrad) - (4)
             Thanks.... - (Fearless Freep)
             Nuther question - (Fearless Freep) - (2)
                 Heh, that seems to have taken care of itself... :-) -NT - (CRConrad) - (1)
                     That was...ironically... - (Fearless Freep)
         Re: Function references in Delphi - (Arkadiy)

Toto... I don't think we're in Kansas anymore...!
66 ms