線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2246
推到 Plurk!
推到 Facebook!

又是TRegistry读取问题

尚未結案
bigdogchina
版主


發表:238
回覆:523
積分:312
註冊:2003-04-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-20 23:15:42 IP:211.162.xxx.xxx 未訂閱
小弟使用TRegistry想将注册表中的一些值读出,但是出错了 我是这样做的: 在头文件中添加 #include  在单元文件中的代码如下 void __fastcall TForm1::Button1Click(TObject *Sender) { TRegistry *RegInfo = new TRegistry(); try { RegInfo->RootKey = HKEY_LOCAL_MACHINE; RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System"); Label1->Caption = RegInfo->ReadString("SystemBiosVersion"); Label2->Caption = RegInfo->ReadString("SystemBiosDate"); Label3->Caption = RegInfo->ReadString("VideoBiosVersion"); Label4->Caption = RegInfo->ReadString("VideoBiosDate"); } __finally { RegInfo->CloseKey(); delete RegInfo; } } 在单击Button1后就会出现错误: Project Project1.exe raised exception class ERegistryException with message 'Invalid data type for 'SystemBiosVersion'.Process stopped.Use Step or Run to continue. 它的意思是说在读取SystemBiosVersion的时候有错误,我打开注册表,发现SystemBiosVersion的类型不是一般的REG_SZ,而是REG_MULTI_SZ,我就不知道该用什么函数来读取了,想请大大们告诉我应该这样来做呢?谢谢 人生在勤,不索何获?
------
人生在勤,不索何获?
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-21 07:13:41 IP:61.224.xxx.xxx 未訂閱
引言: 小弟使用TRegistry想将注册表中的一些值读出,但是出错了 我是这样做的: 在头文件中添加
#include 
在单元文件中的代码如下
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TRegistry *RegInfo = new TRegistry();
    try
    {
         RegInfo->RootKey = HKEY_LOCAL_MACHINE;
         RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System");             Label1->Caption  = RegInfo->ReadString("SystemBiosVersion");
         Label2->Caption  = RegInfo->ReadString("SystemBiosDate");
         Label3->Caption  = RegInfo->ReadString("VideoBiosVersion");
         Label4->Caption  = RegInfo->ReadString("VideoBiosDate");
        }
        __finally
        {
            RegInfo->CloseKey();
            delete RegInfo;
        }
}
在单击Button1后就会出现错误: Project Project1.exe raised exception class ERegistryException with message 'Invalid data type for 'SystemBiosVersion'.Process stopped.Use Step or Run to continue. 它的意思是说在读取SystemBiosVersion的时候有错误,我打开注册表,发现SystemBiosVersion的类型不是一般的REG_SZ,而是REG_MULTI_SZ,我就不知道该用什么函数来读取了,想请大大们告诉我应该这样来做呢?谢谢 人生在勤,不索何获?
必需使用 ReadBinaryData 來讀,例如:
    int iLen;
    char Buf[4096];
    TRegistry *RegInfo = new TRegistry();
    try
    {
        RegInfo->RootKey = HKEY_LOCAL_MACHINE;
        RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System");
        memset(Buf,0,4096);
        iLen=RegInfo->ReadBinaryData("SystemBiosVersion",Buf,4095);
        for(int i=0;iCaption  = String(Buf);
        Label2->Caption  = RegInfo->ReadString("SystemBiosDate");
        memset(Buf,0,4096);
        iLen=RegInfo->ReadBinaryData("VideoBiosVersion",Buf,4095);
        for(int i=0;iCaption  = String(Buf);
        Label4->Caption  = RegInfo->ReadString("VideoBiosDate");
    }
    __finally
    {
        RegInfo->CloseKey();
        delete RegInfo;
    }
使用 TRegistry 要小心,只要型別不對,就是 Exception ! 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell.... 發表人 - dllee 於 2003/06/21 07:16:59
------
http://www.ViewMove.com
chinhung_fu
一般會員


發表:1
回覆:1
積分:0
註冊:2004-03-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-09-30 15:46:30 IP:163.29.xxx.xxx 未訂閱
請問若我想讀取的是此註冊表內的REG_BINARY的值(例如於本路徑的Component Information),我想取得當中00 00 00 00,並將數字文字化,該怎麼做?
系統時間:2024-05-18 6:05:42
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!