delphi – 将类放在DLL中?
发布时间:2020-12-15 04:21:52 所属栏目:大数据 来源:网络整理
导读:是否可以将一些类放入DLL中? 我正在处理的项目中有几个自定义类,并希望将它们放入DLL中,然后在需要时在主应用程序中访问,如果它们在DLL中,我可以在其他项目中重用这些类,如果我需要的话至. 我发现这个链接:http://www.delphipages.com/forum/showthread.ph
是否可以将一些类放入DLL中?
我正在处理的项目中有几个自定义类,并希望将它们放入DLL中,然后在需要时在主应用程序中访问,如果它们在DLL中,我可以在其他项目中重用这些类,如果我需要的话至. 我发现这个链接:http://www.delphipages.com/forum/showthread.php?t=84394讨论了访问DLL中的类,它提到委托给类类型的属性,但我在Delphi帮助或在线中找不到任何关于此的更多信息. 有什么理由我不应该把类放在DLL中,如果没有问题,那么在上面的链接示例中有更好的方法吗? 谢谢 解决方法
无法从DLL获取类/实例.
您可以将接口移交给类,而不是类. 下面是一个简单的例子 // The Interface-Deklaration for Main and DLL unit StringFunctions_IntfU; interface type IStringFunctions = interface ['{240B567B-E619-48E4-8CDA-F6A722F44A71}'] function CopyStr( const AStr : WideString; Index,Count : Integer ) : WideString; end; implementation end. 简单的DLL library StringFunctions; uses StringFunctions_IntfU; // use Interface-Deklaration {$R *.res} type TStringFunctions = class( TInterfacedObject,IStringFunctions ) protected function CopyStr( const AStr : WideString; Index : Integer; Count : Integer ) : WideString; end; { TStringFunctions } function TStringFunctions.CopyStr( const AStr : WideString; Index,Count : Integer ) : WideString; begin Result := Copy( AStr,Index,Count ); end; function GetStringFunctions : IStringFunctions; stdcall; export; begin Result := TStringFunctions.Create; end; exports GetStringFunctions; begin end. 现在简单的主程序 uses StringFunctions_IntfU; // use Interface-Deklaration // Static link to external function function GetStringFunctions : IStringFunctions; stdcall; external 'StringFunctions.dll' name 'GetStringFunctions'; procedure TMainView.Button1Click( Sender : TObject ); begin Label1.Caption := GetStringFunctions.CopyStr( Edit1.Text,1,5 ); end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |