回答
您可以使用.NET組件用Delphi爲.NET這是RAD工作室
不再是了,自Delphi 2009開始,Delphi.NET已經被Delphi Prism所取代。 – 2009-10-27 06:40:59
Delphi for .NET是Rad Studio 2009的一部分 – 2009-11-04 23:08:04
有這樣做的幾種方法和傳統的COM /互操作僅僅是一個辦法做到這一點的一部分。
另一種方法是使用內置於CLR中的現有基礎結構來支持COM/Interop和混合模式C++/CLI。
- 的CLR具有用於編組接口引用,並從IUnknown的出色的支持(而每德爾福接口滿足這一要求)
- 你可以把.NET程序集變成真正的DLL導出功能與任何語言
- 我已經寫了一個MSBuild任務,這是否是完全透明的:http://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
- 結合的兩件事情,你可以得到你的.NET組件的接口參考W/O需要與COM和CLSID的戰鬥/ ProgIDs的
幸運的是,我已經在另一個論壇上回答了一個非常類似的問題。所以我已經有一些示例代碼開始。 ;-)
我在這裏展示的可能不是你的一杯茶。
- 它至少需要一些.Net知識,你可能不想太多介入。
- 在雙方都需要手動步驟,即使您獲得的靈活性可以輕鬆實現,但靈活性可能不是必需條件。因此,傳統的COM可能是一種選擇。
在一天結束時,我不會使用經典的COM自己。除非它真的有道理。 (就像編寫COM-Addins for Office一樣)
在VisualStudio中,可以使用重構/提取界面嚮導從組件中獲取具有所需方法的接口。
您需要提供這3個屬性
[ComVisible(true)]
[Guid("Create a GUID yourself"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IYourInterface
- 「標記有ComVisible特性」要求或CLR將不會創建所需的運行時可調用包裝(RCW)(將從德爾福可以看到的東西)
- GUID是需要識別接口方面,GUID必須是在你的界面
- 「ComInterfaceType.InterfaceIsIUnknown」的Delphi和.NET版本相同告訴了RCW應實現IUnknown的CLR。沒有它,你將無法在德爾福中使用它。因爲在Delphi中,每個接口都是IUnknown。
爲了保持簡單,我假設你的組件只有一個簡單的方法。 在VisualStudio中創建一個類庫,並按照其他頁面中的步驟進行操作。 (爲了能夠導出功能)
[ComVisible(true)]
[Guid("Create a GUID yourself"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IYourInterface
{
void DoSomething(int value);
}
public class YourComponent : IYourInterface
{
public void DoSomething(int value)
{
return value + 1;
}
}
static class Exports
{
[DllExport("createyourcomponent")]
public static void CreateInstance([MarshalAs(UnmanagedType.Interface)]out IYourInterface instance)
{
instance = new YourComponent();
}
}
在Delphi中,如果您願意,可以將此接口包裝在組件中。 這會隱瞞事實,.NET是涉及:
type
IYourInterface = interface
['{Create a GUID yourself}']//Control+Shift+G in Delphi
// important, safecall is used by COM/Interop
procedure DoSomething(aValue : Integer); safecall;
end;
TYourComponent = class(TComponent)
private
fInnerInstance : IYourInterface;
public
procedure DoSomething(aValue : Integer);
constructor Create(aOwner : TComponent);
end;
implementation
procedure CreateManagedInstance(out aInstance : IYourInterface);
stdcall; external 'YourDotNetLibraryName'
name 'createyourcomponent';
constructor TYourComponent.Create(aOwner : TComponent);
begin
inherited Create(aOwner);
CreateManagedInstance(fInnerInstance);
end;
procedure TYourComponent.DoSomething(aValue : Integer);
begin
fInnerInstance.DoSomething(aValue);
end;
聲明:我沒有一個IDE方便,所以有可能是拼寫錯誤或在示例代碼中其他錯誤......
- 1. 如何在Delphi 2010中安裝Delphi 2009組件包(UniSynEdit包)?
- 2. Delphi 2009中的「Delphi基礎知識」
- 3. 在Delphi 2009年
- 4. Delphi 2009中包含QuickReports嗎?
- 5. 在Delphi 2009中掛接Stacktrace
- 6. FitNesse for Delphi 2006/Delphi 2007/Delphi 2009
- 7. Delphi 2009未分配自定義組件事件
- 8. unicode&delphi 2009中的特殊字符
- 9. Delphi 2009中的TShellListView在哪裏?
- 10. Delphi 2009中Indy 10的逐步升級
- 11. 谷歌地圖中的Delphi 2009應用
- 12. 如何在Delphi 2009 CodeGear上安裝COM端口組件?
- 13. Delphi 2009:使用組件包時出現「Class not found」
- 14. Delphi 2009重構錯誤
- 15. Delphi 2009 RawByteString變幻莫測
- 16. CodeGear Delphi 2009商店設置
- 17. Delphi 2009 + Unicode + Char大小
- 18. delphi 2009 unicode + ansi問題
- 19. 將Delphi 2007組件遷移到.NET
- 20. 在Delphi 2009中投射匿名程序
- 21. 從Delphi 2009中提取PNG圖像imagelist
- 22. 基於Delphi 2009中的編譯器指令的條件編譯
- 23. 安裝用於POS的.Net插件2009
- 24. AxaptaContainerWrapper類.net AX 2009
- 25. 如何在Delphi 2009中對自定義組件進行鼠標平移
- 26. Paradox DB和Delphi 2009的InstallAware 9問題
- 27. Delphi 2006中的TPageControl組件
- 28. 如何在Delphi 2009中爲我的組件設置工具調色板組件圖標?
- 29. 在Delphi 2009中檢測TWebBrowser刷新事件
- 30. 在delphi 2009中創建一個gif動畫文件?
什麼樣的組件? – SLaks 2009-10-26 11:50:31