2017-05-16 34 views
1

在FORMCREATE程序我寫:無法找到資源文件的 '權利'

var f: TResourceStream; 
    begin 
    // load data about rights from rights.txt resource file 
    f := TResourceStream.create(Hinstance, 'rights', PChar('RT_RCDATA')); 
    try 
    LoadFromStream(f); 
    finally 
    f.free; 
    end; 

,並得到錯誤:

Project1.exe raised exception class ERESNotFound with message 'Resource rights not found'. 

如果我改變文件路徑 '權利':

'rights.txt'   or 
'D:\Example\rights.txt' or 
'D:\Example\rights' 

我得到同樣的錯誤!

rights.txt文件我在項目文件夾和win32 \ debug \ project1.exe文件夾中找到了這兩個文件,但發生了同樣的錯誤。

更新1

PopupMenu with access rights

rights.txt file for loading popupmenu

這將是在rights.txt文件中的這些不確定simbols?

+0

你有t o通過資源編譯器或後來的delphi版本將RC數據編譯到Res,這可以通過Project,Resources菜單處理,我相信它是,你已經做到了,先不是嗎? – Craig

+0

我在「項目」 - >「資源和圖像」中輸入並添加'rights.txt'文件來資源化,但使用後沒有行出現在項目文件中。我只看到{$ R * .res},並出現相同的錯誤。 德爾福版本:10.1柏林 – Delphi159

+0

我已經在項目管理器中看到'rights.txt'文件,但同樣的錯誤出現。 – Delphi159

回答

3

您需要將ResType參數更改爲RT_RCDATA,而不是PChar('RT_RCDATA')

f := TResourceStream.create(Hinstance, 'rights', RT_RCDATA); 

RT_RCDATASystem.Types單元定義如下

const 
    RT_RCDATA  = PChar(10); 

所以,你也可以使用它像這樣

f := TResourceStream.create(Hinstance, 'rights', PChar(10)); 
+1

如果您要直接指定資源類型而不是使用預定義的常量,則應該使用'MakeIntResource()',例如:'f:= TResourceStream.create(Hinstance,'rights',MakeIntResource(10)) ;' –

+0

我有'rights.txt'文件。在'notapad ++'中我將它重命名爲'rights.rc'。然後在「項目」 - 「資源和圖像」中,我將.rc文件添加到項目中,{$ R'rigths.res''rigths.rc'}出現在Project1.dpr文件中。之後按「Ctrl + F9」,我得到一個錯誤:「源輸入中的壞字符」。 'rights.txt文件'中有很多非打印字符,例如:STX,SOH,GS等 – Delphi159

+0

@ Delphi159保留文件擴展名('.txt')或將其重命名爲其他內容'.rc'並將其添加到資源和圖像中作爲'RCData' **資源類型**那裏,不要忘記從**項目管理器中刪除'rights.rc'文件** – RepeatUntil