Home General

Plugin Question: Saving Registry options to HKEY_LOCAL_MACHINE?

edited September 2001 in General
I am using Delphi 5.0 with RB 6.02.

I am trying to save the ReportBuilder registry keys to the
HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER. We have this as a
command like option for our application.

I am trying create a plug in for the TppRegistry class in the
ppIniStorage unit. I followed the Tech Tip but still is will not accept
it. I warn you this is the first time I have tried to write a plug in so
bare with me.

Here is what I have in my new plug in unit. I think the code should work
providing I can get the plug in to be accepted. I can put a breakpoint
in the create and it never gets executed.

Any comments or suggestions would be great.

--------------- start of code

unit UnitDevRWIniStorage;

interface

uses inifiles, ppIniStorage, proreg, registry;

type
TppdevRegistry = class(TppCustomIniFileStorage)
protected
function CreateCustomIniFile(aStorageName: String):
TCustomIniFile; override;
public
constructor Create(aStorageName: String); override;
class function ClassDescription: String; override;
class function DefaultStorageName: String; override;
end; {class, TppdevRegistry}

implementation

constructor TppdevRegistry.Create(aStorageName: String);
begin
inherited Create(aStorageName);
TRegistryIniFile(CustomIniFile).RegIniFile.RootKey :=
SystemRegistryKey;
end; {function, Create}

{------------------------------------------------------------------------------}

{ TppdevRegistry.CreateCustomIniFile }

function TppdevRegistry.CreateCustomIniFile(aStorageName: String):
TCustomIniFile;
begin
Result := TRegistryIniFile.Create(aStorageName)

end; {function, CreateCustomIniFile}

{------------------------------------------------------------------------------}

{ TppdevRegistry.Description }

class function TppdevRegistry.ClassDescription: String;
begin
Result := 'Registry';

end; {class function, Description}

{------------------------------------------------------------------------------}

{ TppdevRegistry.DefaultStorageName }

class function TppdevRegistry.DefaultStorageName: String;
begin
Result := 'RBuilder';

end; {class function, DefaultStorageName}


initialization

TppIniStoragePlugIns.Register(TppdevRegistry);

finalization

TppIniStoragePlugIns.UnRegister(TppdevRegistry);

end.

---------- end of code

Comments

  • edited September 2001

    1. Simplest way to create this would be to descend from the ppRegistry
    class and override 2 methods:


    TppdevRegistry = class(TppRegistry)
    protected
    function CreateCustomIniFile(aStorageName: String): TCustomIniFile;
    override;
    public
    class function ClassDescription: String; override;
    end;


    function TppdevRegistry.CreateCustomIniFile(aStorageName: String):
    TCustomIniFile;
    var
    lRegistryFile: TRegistrFile;
    begin
    lRegistryFile := TRegistryIniFile.Create(aStorageName)
    lRegistryFile.RegIniFile.RootKey := SystemRegistryKey;

    Result := lRegistryFile;

    end;

    class function TppdevRegistry.ClassDescription: String;
    begin
    Result := 'DevRegistry';

    end; {class function, Description}


    2. Set TppDesigner.IniStorageType to 'DevRegistry'. I think the problem
    with your plug-in is that you the ClassDescription you used is Registry,
    which is one that is already registered by RB.





    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited September 2001
    I tried your example and the plug in is still not being accepted. The registry
    settings are still saved in HKEY_CURRENT_USER while our other application settings are
    in HKEY_LOCAL_MACHINE. I tried the breakpoint again but the CreateCustomIniFile is not
    being executed.

    Here is the updated unit.

    ----- START OF CODE

    unit UnitDevRWIniStorage;

    interface

    uses inifiles, ppIniStorage, proreg, registry;

    type
    TppdevRegistry = class(TppRegistry)
    protected
    function CreateCustomIniFile(aStorageName: String): TCustomIniFile; override;
    public
    class function ClassDescription: String; override;
    end; {class, TppdevRegistry}

    implementation

    {------------------------------------------------------------------------------}
    { TppdevRegistry.CreateCustomIniFile }

    function TppdevRegistry.CreateCustomIniFile(aStorageName: String): TCustomIniFile;
    var
    TempRegFile: TRegistryIniFile;
    begin
    TempRegFile := TRegistryIniFile.Create(aStorageName);
    TempRegFile.RegIniFile.RootKey := SystemRegistryKey;
    Result := TempRegFile;
    end; {function, CreateCustomIniFile}

    {------------------------------------------------------------------------------}
    { TppdevRegistry.Description }

    class function TppdevRegistry.ClassDescription: String;
    begin
    Result := 'DevRegistry';
    end; {class function, Description}

    initialization

    TppIniStoragePlugIns.Register(TppdevRegistry);

    finalization

    TppIniStoragePlugIns.UnRegister(TppdevRegistry);

    end.
    --------- END OF CODE

  • edited September 2001
    Sorry to post this question again. But I still haven't received a response.

  • edited September 2001

    Works fine when I try it here - although I do not seem to have write key
    access to HKEY_LOCAL_MACHINE.

    Make sure that you setting the TppDesigner.IniStorageType to
    'DevRegistry' and including the UnitDevRWIniStorage in the 'uses' clause
    of your application.

    In your application you need something like this:

    uses
    UnitDevRWIniStorage;

    begin

    myDesigner.IniStorageType := TppdevRegistry .ClassDescription;
    myDesigner.IniStorageName := 'RBuilder'; {or whatever name you want to
    use}
    myDesigner.ShowModal;

    end;








    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited September 2001
    Thanks for sticking with this problem. This doesn't seem to want to work. Some one else must
    have tried this before. Or suggested an additional property of the Designer to state the
    RootKey.

    Setting TppDesigner.IniStorageType to DevRegistry made my plugin get executed. Unfortunately
    it does not save the registry into the correct area. The TRegistryIniFile.Create method
    creates an empty registry key in HKEY_CURRENT_USER before I get a change to tell the
    TRegisitryIniFile to point to HKEY_LOCAL_MACHINE. I would be ok with that but the same
    registry key is not created in HKEY_LOCAL_MACHINE. Instead it saves all of the designer
    properties into keys directly under HKEY_LOCAL_MACHINE instead of in the desired path.

    Here is the code changed I made to the form create of the form that has the Designer on it.

    ppDesigner.IniStorageType := TppdevRegistry.ClassDescription;
    ppDesigner.IniStorageName := 'Software\Dev\App\ReportWriter\Settings';

    The properties I have set by default in the object inspector are:

    ppDesigner.IniStorageType := 'Registry';
    ppDesigner.IniStorageName := 'Software\Dev\App\ReportWriter\Settings';

    Any thoughts?

    I really need to find an answer to this one. Thanks.


  • edited October 2001

    Sorry for the delay did not see this post.

    1. I am not an expert on TRegistryIniFile so I am not really qualified
    to answer the question.

    2. I do know that TppIniStorage is constructed such a way as to support
    ANY type of storage. The internal implementation details are left to the
    developer.

    3. I would think the RegistryIniFile would have a way to work. But you
    can always use another approach. I would spend some time playing around
    with TRegistryIniFile outside of ReportBuilder. Just try creating a
    TRegistryIniFile instance and try storing keys to the location you want.

    4. I do not know why in the ObjectInspector for Designer you have

    ppDesigner.IniStorageType := 'Registry';

    That is incorrect. That Registry value is used for the RB TppRegistry
    class.

    Your custom class should have its own description - I think you need
    something like

    ppDesigner.IniStorageType := 'DevRegistry';


    Try modifying the libarary path from RBuilder\Lib to RBuilder\Source and
    then trace the source code.





    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.