Hi,

[I'm posting this here, seeing that I got no response from the FPC
Users mailing list. I guess nobody there uses Interfaces.]

I'm pretty new to using interfaces... I want to use interfaces so that
I can spot problems at compile time and not runtime.  For example: If
I used a base class with abstract methods and then created descendant
classes. Now if I forgot to implement one of the abstract methods which gets
called somewhere...  I'll only find the problem at runtime (with an
abstract error) and not
compile time.

I would rather like to be told about this problem at compile time. I'm
hoping that Interfaces will solve this issue.  Am I allowed to do the
following?

With my preliminary testing this seems to work. As soon as I leave out
one of the IWindowImpl interface methods from the TX11Window class,
the compiler complains. Exactly what I want.  :-)

Also can I let my base class descend from TComponent instead of
TInterfacedObject? Looking at the declaration of the TComponent class,
it implements IUnknown, so I guess I am allowed to add more interfaces
in descendant classes.

type
IWindowImpl = interface;

IWindowImpl = interface(IInterface)
  ['{BDBC9BE7-77E0-4EA1-B40B-282CE06A32B3}']
  procedure DoAllocateWindowHandle(AParent: IWindowImpl);
  procedure DoSetWindowTitle(const ATitle: string);
end;

TBaseImpl = class(TComponent)
private
  FHeight: integer;
  FWidth: integer;
  procedure SetHeight(const AValue: integer);
  procedure SetWidth(const AValue: integer);
public
  property  Width: integer read FWidth write SetWidth;
  property  Height: integer read FHeight write SetHeight;
end;

TX11Window = class(TBaseImpl, IWindowImpl)
protected
  procedure DoAllocateWindowHandle(AParent: IWindowImpl);
  procedure DoSetWindowTitle(const ATitle: string);  // leaving this
out would give a compiler warning. Yes!
end;


Aside from my initial question, Is there any things I need to watch
out for? Things being garbage collected before I am actually done with
them, etc..


Regards,
- Graeme -

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to