我要投稿
  • 您当前的位置:57365.com -> 技术教程 -> 软件开发教程 -> Delphi教程 -> 教程内容
  • [ 收藏本页教程 ]
  • DELPHI和注册表Delphi教程

    教程作者:佚名    教程来源:不详   教程栏目:Delphi教程    收藏本页
     

    0. DISCLAIMER:
    1. What is the registry?
    2. What does the registry look like?
    3. How to read and write data to the registry
        3.1 RegCreateKey()
        3.2 RegOpenKey()
        3.3 RegSetValue()
        3.4 RegQueryValue()
        3.5 RegDeleteKey()
        3.6 RegEnumKey()
    4. An Example
    5. Win95 features
    6. REGDLL.DLL

    The source code corresponding to this article is available for download as
    registry.zip.
     
     

    0. DISCLAIMER:

    This article reflects my personal experiences with the registry and Delphi.
    I had no 'real' documentation on this, except what shipped with Delphi. I
    will not take any responsibility that occurs from the usage of the
    procedures described in this article. The same applies to the usage of the
    accompanying REGDLL.DLL and its interface. USE AT YOUR OWN RISK.

    Suggestions and Comments are welcome. Please send them to:
    Christian.Feichtner@jk.uni-linz.ac.at.

    This article describes how to use the registry-database as an 'INI file'.
    Especially with the advent of Windows 95 every 'good' windows application
    should use the registry database to store its information.

    Note that the described API routines are from the 16bit API. They work well
    with the registry of Windows 95, but are not capable of using the special
    new features of Windows 95.
     
     

    1. What is the registry?

    The registry is a heirarchical database, which is used to store information
    for the whole system. OLE-apps made frequent use of the registry in Win31.
    In Windows 95 the registry has grown to more than that. It not only stores
    system information but has become a total replacement for the old-style INI
    files. The INI files are only supported to maintain compatibility for 'old'
    16bit Apps.
     
     

    2. What does the registry look like?

    As mentioned above, the registry is a heirarchical database. It is
    organized as a tree. The most interesting key (and the only one accessable
    from Delphi with the 16bit version) is the HKEY_CLASSES_ROOT.

    This key can be used to store application settings. (Thus, I think there is
    another key for Windows 95 apps. Since Delphi can only access this key, you
    can use it until Delphi-32 becomes avaliable).

    Example:

     + HKEY_CLASSES_ROOT      This is what a key could look like. Assume an
     |                        application named Information Manager (which I'm
     +--+-.IFM                currently developing) which saves its files with the
        |                     extension .IFM.  Under Win95 the shell, open, command
        +--+-shell            and ShellNew keys are of special interest. (Yes they
           |                  can be used with Delphi as well.)
           +--+-open
           |  |
           |  +---command
           |
           +-ShellNew

    .IFM\shell\open\command defines the command to be executed when the user
    double clicks on the file (or under Win95 hits the right mouse button and
    selects open).

    The keys alone won't do the job. Normally there are values assigned to the
    keys. Under Win31 these can only be strings. Win95 defines a kind of binary
    and a DWORD as well.

    The shell\open\command normally has a value like:

                                Name          Value
     + HKEY_CLASSES_ROOT
     |
     +--+-.IFM
        |
        +--+-shell
           |
           +--+-open
           |  |
           |  +---command     (default)     "H:\PROJECT\INFOMAN\IFM.EXE %1"
           |
           +-ShellNew

    The selected filename will be substituted for '%1' and passed along as a
    command-line parameter to the application. Your Delphi app can use
    PARAMSTR(x) to get the x-th command line parameter. x=0 returns the full
    path and name of the application itself.

    If you are using the preview of Win95 and want your application to have an
    entry in the 'New' popup menu (something like 'Information Manager 1.0
    file'), you have to do the following:

    Add a new (text) value for the ShellNew key, named NullFile, with a value
    of "". Also name the extension (.IFM) equal to the entry of your app in the
    registry. If the application has an entry named 'InfoMan', then name .IFM
    as InfoMan.

    Example:

             

    我要投稿   -   广告合作   -   关于本站   -   友情连接   -   网站地图   -   联系我们   -   版权声明   -   设为首页   -   加入收藏   -   网站留言
    Copyright © 2009 - 20012 www.www.hxswjs.com All Rights Reserved.57365.com 版权所有