Board index » delphi » Complex Base/Derived-class problem

Complex Base/Derived-class problem

I have a very complex problem:

I want to derive a func from a base-class, but want the member-fn of the
base class to have control.
All together: I want to derive a function, while some code (of the
base-func) is automatically executed before the derived mem-func is
executed and some code afterwards.
In other words: I want to have functionality of the "inherited;" command,
only I want it to work from a base class to a derived class.

I don't bother using some extra variables or functions, if it only works!

Please Help!

-------------------------------------
             O. Kerssens
-------------------------------------

               \|||||/
               (.) (.)
 /----------oOOo-(_)-oOOo----------\
|                                  |\
|        I'm not curious           ||
|  I just want to know everything  ||
|                                  ||
|     O.Kerss...@innocent.com      ||
|                                  ||
|          .oooO     Oooo.         ||
 \---------(   )-----(   )--------/ |
   \--------\ (------ ) /----------/
             \_)     (_/

 

Re:Complex Base/Derived-class problem


Oscar

I think I am right in saying that if you name the function in the derived
class slightly differently from the base version then you call the base
version, do whatever you need to in there and then call the derived
function with the class name as a qualifier:

e.g.

function TBaseClass: Thing
begin
  Do Bits in Base Class...
  Result := TDerived.Thingy;
end;

Of course you should be working with an instance of the derived class in
order for this to work.

Try that and let me know.

Joan...@compuserve.com

Oscar Kerssens <o.kerss...@freemail.nl> wrote in article
<01bcabf6$9b556260$110aa...@pip.inter.nl.net>...

Quote
> I have a very complex problem:

> I want to derive a func from a base-class, but want the member-fn of the
> base class to have control.
> All together: I want to derive a function, while some code (of the
> base-func) is automatically executed before the derived mem-func is
> executed and some code afterwards.
> In other words: I want to have functionality of the "inherited;" command,
> only I want it to work from a base class to a derived class.

> I don't bother using some extra variables or functions, if it only works!

> Please Help!

> -------------------------------------
>              O. Kerssens
> -------------------------------------

>                \|||||/
>                (.) (.)
>  /----------oOOo-(_)-oOOo----------\
> |                                  |\
> |        I'm not curious           ||
> |  I just want to know everything  ||
> |                                  ||
> |     O.Kerss...@innocent.com      ||
> |                                  ||
> |          .oooO     Oooo.         ||
>  \---------(   )-----(   )--------/ |
>    \--------\ (------ ) /----------/
>              \_)     (_/

Re:Complex Base/Derived-class problem


On 18 Aug 1997 17:47:44 GMT, "Oscar Kerssens" <o.kerss...@freemail.nl>
wrote:

Quote
>All together: I want to derive a function, while some code (of the
>base-func) is automatically executed before the derived mem-func is
>executed and some code afterwards.
>In other words: I want to have functionality of the "inherited;" command,
>only I want it to work from a base class to a derived class.

Would it work to have your base class call a virtual method?

TBaseClass = Class
  Procedure BaseProc;
  Procedure SpecProc; virtual;
  end;

TDerivedClass = Class(TBaseClass)
  Procedure SpecProc; override;
  end;

Procedure TBaseClass.BaseProc;
  begin
  { Do some stuff }
  ...
  SpecProc;
  { Do some other stuff }
  ...

  end;

Note that the program that calls TDerivedClass.BaseProc does not know
anything about SpecProc.

Brian

Re:Complex Base/Derived-class problem


Hi Oscar,

Why don't you use virtual methods. This will give you something like:

BaseObject = class
protected
  function SpecialAction( Params : double ) : double; virtual;
public
  procedure DoSomething;
end;

Object1 = class( BaseObject )
protected
  function SpecialAction( Params : double ) : double; override;
end;

Object2 = class( BaseObject )
protected
  function SpecialAction( Params : double ) : double; override;
end;

BaseObject's DoSomething will execute some code, call the virtual method
SpecialAction
and possibly do some more stuff.

So the implementation will look something like this:

function BaseObject.SpecialAction(Params : double ) : double;
begin
  Result := Params;
end;

procedure BaseObject.DoSomething;
begin
  { Do some stuff }
  SpecialAction;
  { Do some more stuff }
end;

Hope this helps,

  Willo

Re:Complex Base/Derived-class problem


Willo, thanx 4 looking @ the problem.

This one I figured out also. This could be the solution if everything else
fails. What I like to achieve is that I continuously rewrite the
"SpecialAction" but want the "SpecialAction" of the base-class to be
carried out automatically. This problem can cover up to 4 levels. So I
still hope to find the solution to my problem...

Re:Complex Base/Derived-class problem


Can u tell me how these dynamic object pointers work, and is it possible to
get the different pointers for the same methods in the base and derived
class?

I have the feeling that this could be the solution to my problem...

Willo <n...@spam.me> wrote in article <01bcb451$2a2d6520$882b19c4@willow>...

Quote
> Hi Oscar,

> You could also use object method pointers, like the Delphi events. This
> allows your system to be extremely dynamic, since you can switch between
> different functionalities on the fly. Perhaps, normal function pointers
> would do too?

Other Threads