2011-03-02 25 views
3

我得到一個錯誤,我不知道爲什麼我得到它...德爾福:設計模式中的「資源未找到」 - 爲什麼?

所以:我有一個新的組件,基於sAlphaButton。 這有ImageList屬性,我的組件擴展此按鈕與我自己的字幕/圖像,翻譯成匈牙利語。

我用LoadRes來獲取預定義的圖像。

看到這個:

procedure TScrollPNGButton.LoadAsImageListFromRes(ResNames : TStrings; IL : TsAlphaImageList); 
var 
    s : string; 
    i : integer; 
begin 
    IL.CLear; 
    for i := 0 to ResNames.Count - 1 do begin 
     s := ResNames[i]; 
     AddImageFromRes(hInstance, IL, s, ifPNG); 
    end; 
end; 


procedure TScrollPNGButton.LoadResToImageList; 
var 
    sl : TStringList; 
begin 
    sl := TStringList.Create; 
    try 
     sl.Text := 
      Trim(
        'scrollpngbutton_ok'#13 + 
        'scrollpngbutton_cancel'#13 + 
        'scrollpngbutton_close'#13 + 
        'scrollpngbutton_yes'#13 + 
        'scrollpngbutton_no'#13 + 
        'scrollpngbutton_refresh'#13 + 
        'scrollpngbutton_print'#13 + 
        'scrollpngbutton_email'#13 + 
        'scrollpngbutton_add'#13 + 
        'scrollpngbutton_delete'#13 + 
        'scrollpngbutton_edit'#13 + 
        '' 
       ); 
     LoadAsImageListFromRes(sl, FImgs); 
    finally 
     sl.Free; 
    end; 
end; 


constructor TScrollPNGButton.Create(aOwner : TComponent); 
begin 
    inherited Create(aOwner); 
    FImgs := TsAlphaImageList.Create(nil); 
    inherited Images := FImgs; 
    LoadResToImageList; 
end; 

當我使用它的代碼它的工作好。 但當我註冊的,我嘗試投入形式,我得到了錯誤:

Error Resource scrollpngbutton_ok not found. OK

我不明白,因爲我把{$ R * .RES},並從這個代碼工作中。 爲什麼找不到資源?創作失敗了,還是什麼?

好的,我可以使用Loaded;在設計時設置圖像,但Loaded不在運行時調用。

+0

什麼是'TsAlphaButton'? [Google](http://www.google.se/search?sourceid=chrome&ie=UTF-8&q=TsAlphaButton)不知道。 – 2011-03-02 16:35:18

+0

在哪個文件中您有$ R指令? – jachguate 2011-03-02 16:44:19

+0

AlphaSkin組件。現在我發現錯誤的來源,他們使用hInstance,什麼是不平等我的實例。我糾正了他們的代碼。謝謝你的幫助! dd – durumdara 2011-03-03 12:31:14

回答

11

您不能使用* .res。這是IDE生成的與DFM /單元名稱匹配的文件。

創建您自己的資源文件(您可以將其創建爲文本文件)並自己編譯(或者如果您使用的是Delphi 7或更高版本,請讓IDE爲您完成)。

/* YourResources.rc */ 
SCROLLPNGBUTTON BITMAP MyBitmap.bmp 

在源:

{$R YourResources.res YourResources.rc} // The IDE will compile .rc to make .res 
+0

+1;這是你很容易出錯的事情。 – 2011-03-02 21:50:12