Shared project

Hi,

I’m trying to use Shared Project with simple interface - IInpxTable.

Then I’ve a ClassLib Common with a reference to Shared and a class TInpxTable that implements IInpxTable.

The next ClassLib TestClassLib with a reference to Common ClaccLib, contains interface
IInpxTestTable = public interface(IInpxTable)
and a class
TInpxTestTable = public class(TInpxTable, IInpxTestTable)

It works, but when I add a reference in TestClassLib to Shared Project it fails to compile.

The question is - is it possible to use Shared Project in multiple projects or there should be only one project with a reference to shared and other project should have reference to it?

TestSharedProject.7z (12.2 KB)

Mateusz,

Your project not only looks good it compiles fine for me, here. What’s the exact error you are getting?

of course. the whole point is that multiple “real” projects can reference the shared project.

Error I have - error E182: Event “AddedOrEdited” add accessor not implemented as required for interface “SharedProject.IInpxTable”

Of course without any changes to uploaded code :wink:

WIthout referencing Shared Project to Class Library everything works fine.

At that point you’re defining:

type
  ItemAddedOrEditedEventHandler = public delegate;

  IInpxTable = public interface
    event AddedOrEdited: ItemAddedOrEditedEventHandler;
  end;

Twice; once in Common (which implements it in TInpxTable) and once in TestClassLib which descends from that. Now you have TWO ItemAddedOrEditedEventHandler types, and they’re not compatible.

TInpxTable implements IInpxTable and have AddedOrEdited event.
Than TInpxTestTable inherits from TInpxTable where AddedOrEdited is implemented but it seems that complier don’t see it.

I’ve added

  IInpxtable2 = public interface(IInpxTable)
    event AddedOrEdited: ItemAddedOrEditedEventHandler;
  end; 

and changed

  TInpxTable = public class(IInpxtable2)
  private
  protected
  public
    event AddedOrEdited: ItemAddedOrEditedEventHandler;
  end;

than

  IInpxTestTable = public interface(IInpxTable)
  end;

and

  TInpxTestTable = public class(TInpxTable, IInpxTestTable)
  end;

and everyting works fine.
Why without shared project it works different? I don’t uderstand why ‘TWICE’ - it inherits and shuldn’t be TWICE.

You use shared projects. They’re not the same as libraries but they get included in each project seperately. So you have two copies of both ItemAddedOrEditedEventHandler and IInpxTable, which is causing this.

So the best way to achieve what I want is to make library with a reference to Shared and not to add a refenernce to Shared but this library.

Yes, or not use shared at all, this is a problem that can just as well be solved with class libraries.

Problem can be solved with class libraries but it won’t be usable on other platforms.

Basically you’ll want to use EITHER a shared project OR a library. there’s not much sense in using both at the same time.

I want to use Shared Project to include there my interfaces. Than on each platform I would like to create Class Library with implementation of those shared interfaces.

That would work yes.

Yes - that works, but I can’t reference Shared Project in any other Class Library.

You can, what you can’t do is have it included in two projects that use eachother on the same platform. Every type is unique identified both by the library it’s in and the type name.