0
votes

So basically here is what I did:

I made a new FMHD Application and dropped a TTabControl and a Button on it. Then I designed an interface IFoo. To keep it simple, let's just pretend it only has one procedure:

type
  IFoo = interface
  ['{D035-N07-M4773R-...}']

    procedure makeTab(tc : TTabControl);

  End;

I implemented this interface in a DLL. The DLL is loaded via LoadLibrary and exports a
function getFoo : IFoo;

MakeTab basically creates a TTabItem and sets tc as it's parent:

procedure TFoo.makeTab(tc : TTabControl);
var
  tab
  : TTabItem;
begin
  tab := TTabItem.Create(tc);
  tab.text := 'Hi, I am Tab';
  tab.Parent := tc;
  // ...
end;

If I forgot something, I am very sorry. I do not have the exact source in front of me at the moment.

This method is invoked when the Button on the form is pressed.
But nothing happens.
So I put this method into my TForm1 class. If I call it now, a tab is created.
So how can I create this tab (and several child components) from within the DLL on the application's main form?

1
You need to use packages. Because you've got two instances of FMX in your app. One in the exe and one in the DLL.David Heffernan
yeah, thanks, that works! Sow... maybe you could write the solution as response so I can accept it as answer?Marco Alka

1 Answers

1
votes

The fundamental issue here is that you cannot share Delphi class types between modules using DLLs. The reason is that there will be multiple versions of what needs to be a single type. One version in the executable, and one version in each DLL that uses it.

This is the same well known issue that exists with the VCL and is the reason why runtime packages were developed. And that's your solution for FMX also. If you need to share Delphi class types between modules you need there to be one single definition of a type. And runtime packages are the mechanism that makes that possible.

So, stop using DLLs, move the code into a runtime package, make sure that the RTL and FMX are linked using runtime packages, and that problem will be solved.