我正在使用C Builder,并使用Delphi樣本代碼來呼叫一個新的幫助檔案系統eViewer。當我轉換下面的Delphi程式時,變數IHelpSystem出現了錯誤:變數型別'System::Helpintfs::IHelpSystem'是一個抽象的類。錯誤文本如下。我怎樣才能在C Builder中使用變數IHelpSystem和函式GetHelpSystem呢?
/Original Delphi
procedure TFrmHelpViewerMain.btnShowTopicClick(Sender: TObject);
var
幫助系統。IHelpSystem。
begin
GetHelpSystem(HelpSystem)。
if assigned(HelpSystem) then
HelpSystem.ShowTopicHelp('topic3', Application.HelpFile)。
end。
//My C Builder代碼
#include <System.HelpIntfs.hpp>
void __fastcall TForm99::btnShowTopicClick(TObject *Sender)
{
IHelpSystem HelpSystem; //<< 錯誤在這里
GetHelpSystem(HelpSystem)。
如果( Assigned(HelpSystem) ){
HelpSystem->ShowTopicHelp("topic3", Application-> HelpFile)。
}
}
[bcc64 Error] CBtest_Unit1.cpp(97): variable type 'System::Helpintfs::IHelpSystem' is an abstract class[/p>
- unknwn.h(114): 'IHelpSystem'中未實作的純虛擬方法'QueryInterface' 。
- unknwn.h(118):'IHelpSystem'中未實作的純虛擬方法'AddRef' 。
- unknwn.h(120):'IHelpSystem'中未實作的純虛擬方法'Release' 。
- System.HelpIntfs.hpp(66):'IHelpSystem'中未實作的純虛擬方法'ShowHelp' 。
- System.HelpIntfs.hpp(67):'IHelpSystem'中未實作的純虛擬方法'ShowContextHelp' 。
- System.HelpIntfs.hpp(68):'IHelpSystem'中未實作的純虛擬方法'ShowTableOfContents' 。
- System.HelpIntfs.hpp(69): 'IHelpSystem'中未實作的純虛擬方法'ShowTopicHelp' 。
- System.HelpIntfs.hpp(70):'IHelpSystem'中未實作的純虛擬方法'AssignHelpSelector' 。
- System.HelpIntfs.hpp(71):'IHelpSystem'中未實作的純虛擬方法'Hook' 。
以下是 Embaradero 網站中討論 IHelpSystem 的幫助頁面。
uj5u.com熱心網友回復:
正如錯誤資訊所說,IHelpSystem是一個抽象類(它有純虛擬方法,在派生類中實作),因此你不能直接實體化它,就像你在 C 代碼中嘗試的那樣:
IHelpSystem HelpSystem。
您只能通過指標(IHelpSystem*)或參考(IHelpSystem&)來宣告該型別的變數。而事實上,C 相當于Delphi的宣告:
var HelpSystem: IHelpSystem。
是:
IHelpSystem* HelpSystem;
但是,由于IHelpSystem是一個基于Delphi的介面,你實際上需要使用_di_IHelpSystem包裝型別(它是DelphiInterface<HelpSystem>),這就是GetHelpSystem()在 C 中實際輸出的內容:
extern DELPHI_PACKAGE bool __fastcall GetHelpSystem(/* out */ _di_IHelpSystem & System)/* overload */。
嘗試這樣做:
#include <System.HelpIntfs.hpp>/span>
void __fastcall TForm99::btnShowTopicClick(TObject *Sender)
{
_di_IHelpSystem 幫助系統。
GetHelpSystem(HelpSystem)。
if (HelpSystem)
HelpSystem->ShowTopicHelp(_D("topic3"), Application-> HelpFile);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/329631.html
標籤:
