If I understand the dilemma correctly an interface could be used, as per the
example code below.  They key to it is the implements directive. (look up
the "implements, interfaces" in the delphi help.  Its only available in D4
inwards though.)

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

ISharedCode = interface(IUnknown)
  [GUID]
  function DoSomething : integer;
end;

TSharedCode = class(TInterfacedObject, ISharedCode)
public
  function DoSomething : integer;
end;

TSomeOtherClass = class(TComponent, iSharedCode)
private
  fSharedCode : ISharedCode;
public
  constructor Create(AOwner: TComponent); override;

  property SharedCode : ISharedCode read fSharedCode impliments ISharedCode;

end;

function TSharedCode.DoSomething : integer;
begin
// does something
end;

constructor TSomeOtherClass.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  fSharedCode := TSharedCode.Create;
end;

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

This means that you can call the following - ASomeOtherClass.DoSomething -
which calls the appropriate method from the instance of TSharedCode within
the TSomeOtherClass instance directly without having to have stub methods.

NOTE:  This is how I believe it works, I've not had a situation where I've
had to use it yet.  After reading the help I believe that the above code
should work.


Hope that helps.

Nahum Wild
Game Designer
Realism Ltd

Pre-Register now for the ESDAO beta test!
http://www.esdao.net


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Mike Mueller
> Sent: Saturday, September 02, 2000 14:20
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Multiple Inheritance?
>
>
> You can't have multiple inheritance in Delphi (or Java).  You can in some
> types of C++.  You *can* have interfaces but that doesn't solve your
> problem.  The reason they don't put it in is because of worry about what
> happens when ancestor methods 'collide' etc..
>
> I suggest creating a TSharedCode in each of your other objects but rather
> than put stub/proxy methods in, access the methods via a public read-only
> reference to TSharedCode
>
> ie.
>
> TComponent1 = class (TQuery)
> private
>   FSharedCode : TSharedCode;
> public
>   property SharedCode : TSharedCode read FSharedCode;
> ... (create/destroy it of course)
>
> and then call the functions with
>
> <some TComponent1Object>.SharedCode.SomeFunction
>
> Mike "gonna stick with the SQL kludge" Mueller
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> > Behalf Of Mark Derricutt
> > Sent: Sunday, 3 September 2000 12:39
> > To: Multiple recipients of list delphi
> > Subject: [DUG]: Multiple Inheritance?
> >
> >
> > 'lo, question for the masses...
> >
> > I have a group of components that all share a common logic, but
> due to the
> > nature of the components, I can't put that common logic in a
> masterclass,
> > at the moment I have:
> >
> > type
> >   TSharedCode = class(TObject)
> >   TComponent1 = class(TQuery)
> >   TComponent2 = class(TADOQuery)
> >   TComponent3 = class(TSomeMemoryTableComponent)
> >
> > TSharedCode has a selection of methods and properties that do the actual
> > grunt code, TComponent1/2/3 create an instance of TSharedCode in their
> > constructor, and have stub/proxy methods defined, so I have:
> >
> > procedure TSharedCode.SomeFunction;
> > begin
> >   // do stuff
> > end;
> >
> > procedure TComponent1.SomeFunction; // this is repeated for
> each component
> > begin
> >   SharedObject.SomeFunction;
> > end;
> >
> > This makes for some messy code, having all these little stub
> functions, so
> > was wondering if I could use multiple inheritance for this?  like:
> >
> > type
> >   TComponent1 = class(TQuery, TSharedCode);
> >
> > This way, if I add functionality to TSharedCode, its instantly available
> > to the other classes without adding new stub functions everywhere.
> >
> > If I had windows/delphi here at home I'd prolly load it up and
> try it, but
> > alas no.
> >
> > Mark
> >
> > ------------------------------------------------------------------
> > ---------
> >     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> >                   Website: http://www.delphi.org.nz
> > To UnSub, send email to: [EMAIL PROTECTED]
> > with body of "unsubscribe delphi"
>
> ------------------------------------------------------------------
> ---------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
>

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to