首页  编辑  

读写Multi_SZ的数据

Tags: /超级猛料/Registry.注册表和INI/   Date Created:

读写Multi_SZ的数据?

如何编程更改注册表的REG_MULTI_SZ型的值?

Kingron:Like this:

type

  TRegistryEx = class ( TRegistry )

  public

    function ReadWideString ( const Name : string ): WideString ;

    procedure WriteWideString ( const Name : string ; Value : WideString );

    function ReadMultiString ( const Name : string ): string ;

    procedure WriteMultiString ( const Name , Value : string );

  end ;

implementation

{ TRegistryEx }

function TRegistryEx . ReadMultiString ( const Name : string ): string ;

var

  L : integer ;

begin

  L := GetDataSize ( Name );

  SetLength ( Result , L );

  RegQueryValueEx ( CurrentKey , pchar ( Name ), nil , nil , PByte ( Result ),@ L );

end ;

procedure TRegistryEx . WriteMultiString ( const Name , Value : string );

const

  REG_MULTI_SZ = 7 ;

begin

  RegSetValueEx ( CurrentKey , pchar ( Name ), 0 , REG_MULTI_SZ , pchar ( Value ), Length ( Value ));

end ;

function TRegistryEx . ReadWideString ( const Name : string ): WideString ;

var

  L : integer ;

begin

  L := GetDataSize ( Name );

  SetLength ( Result , L div 2 );

  if L > 0 then ReadBinaryData ( Name , Result [ 1 ], L );

end ;

procedure TRegistryEx . WriteWideString ( const Name : string ; Value : WideString );

var

  L : integer ;

begin

  L := Length ( value );

  if L > 0 then WriteBinaryData ( Name , Value [ 1 ], L * 2 );

end ;

procedure TForm1 . Button1Click ( Sender : TObject );

begin

  with TRegistryEx . Create do

  try

    if OpenKey ( '' , True ) then

      WriteMultiString ( 'Test' , Memo1 . Text );

  finally

    Free ;

  end ;

end ;

procedure TForm1 . Button2Click ( Sender : TObject );

begin

  with TRegistryEx . Create do

  try

    if OpenKey ( '' , True ) then

      Memo1 . Text := ReadMultiString ( 'Test' );

  finally

    Free ;

  end ;

end ;