Jump to content
FOV

MacOS's dylib doesn't work fine.

Recommended Posts

I used Delphi 11.3 to compile a macOS dylib ,  write a function to create a form and show it on the screen, then I went into macOS and write a program using dlopen to open this dylib and execute the showform function. Here comes the problems, First, click this form's button has no response; Second, when I close the form, commandline will show a warning twice: 
"objc[721]: objc_disposeClassPair: class 'FMXWindow' still has subclasses, including 'NSKVONotifying_FMXWindow'!"
Do I use the wrong way to use the dylib or show the form? Anyone knows how to fix this?

Here is the function in the dylib's Unit1.pas:

function Showform():Integer; stdcall;
begin
    form1:= TForm1.Create(nil);
    Writeln('Execute Showform function from dylib.');
    try
        form1.ShowModal;
        Writeln('form1 showed.');
    finally
        Writeln('Need to Destroy form1.');
        form1.Destroy;
        Writeln('form1 destroyed.');
    end;
    result:= 0;
end;

exports
    Showform;

and this is the program to use the dylib:

#include  
#include  
#include  
#include  
#include "dylibhello.h"  
  
int main()  
{  
	//printf("1: Open the dylib.\n");  
	void* handle = dlopen("/Users/mac13/dylib/libdylibtest.dylib", RTLD_NOW);    
	if(!handle){  
		return -1;  
	}  
  
	//printf("2: Get function's address.\n");  
	void *symbol = dlsym(handle, "Showform");  
	if(!symbol)  
	{  
		dlclose(handle);  
		return -1;  
	}  
  
	//printf("3:Execute the function.\n");  
	void (*fp)() = (void (*)())symbol;  
	fp();  
  
	//printf("4:Close the handle and quit.\n");  
	dlclose(handle); 
     
	return 0;  
}

ps: My test macOS is Ventura 13.5.
 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×