2012-10-31 34 views
0

我想在我的德爾福棱鏡計劃導入DLL和以前從未做過。所以,在網上找到答案之後,我把下面的東西放在一起,但不起作用。如何導入在德爾福棱鏡DLL?

MyUtils = public static class 
    private 
    [DllImport("winmm.dll", CharSet := CharSet.Auto)] 
    method timeBeginPeriod(period:Integer):Integer; external; 
    protected 
    public 
    constructor; 
    end; 

這是我如何使用它:

var tt := new MyUtils; 
tt.timeBeginPeriod(1); 

當我運行我的程序,我不斷收到以下錯誤。

  • 「MyUtils」不提供可訪問的構造函數。
  • 「System.Object的」 不包含 「timeBeginPeriod」 的定義,在表達 「tt.timeBeginPeriod」。

我在做什麼錯?如何在delphi-prism中導入dll?

我跟着這個計算器的問題 - Delphi Prism getting Unknown Identifier "DllImport" error

回答

1

你非常接近。

你不需要構造函數,這樣你就可以將其刪除:

MyUtils = public static class 
private 
    [DllImport("winmm.dll", CharSet := CharSet.Auto)] 
    method timeBeginPeriod(period:Integer):Integer; external; 
protected 
public 
end; 

如果你調用從那裏它被聲明的單元外timeBeginPeriod功能,你需要改變它的知名度public

你也不需要創建一個實例調用該函數:

MyUtils.timeBeginPeriod(1); 

我與聲明和使用SendMessage而不是一個應用程序測試這一點,所以我可以很容易地檢查,以確保其實際工作(I發送的EM_SETTEXT消息編輯控件相同的形式上)。

+0

它的工作原理。謝謝。 – ThN

1
MyUtils = public static class 
    public 
    [DllImport("winmm.dll", CharSet := CharSet.Auto)] 
    class method timeBeginPeriod(period:Integer):Integer; external; 
    end; 


MyUtils.timeBeginPeriod(1); 
+0

CK。謝謝。我的確改變了,就像你在答案中一樣,而且很有效。現在,我確實有一個問題。我能把這個程序在Linux與WINMM.DLL一起下單運行呢?它會按預期工作嗎? – ThN