Recent

Author Topic: TRegistry and String Value - problem  (Read 8876 times)

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
TRegistry and String Value - problem
« on: October 11, 2004, 05:29:35 pm »
I have tried to read a registry value (HKEY_CURRENT_USER\Control Panel\Colors -> ButtonFace), but a code, which works on Delphi:
Code: [Select]
Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_CURRENT_USER;
  Reg.OpenKey('Control Panel\Colors',True);
ShowMessage(Reg.ReadString('ButtonFace')+';'+IntToStr(Length(Reg.ReadString('ButtonFace'))));

doesn't work properly on Lazarus. Why?

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
TRegistry and String Value - problem
« Reply #1 on: October 12, 2004, 11:57:48 am »
What error do you get ?
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
TRegistry and String Value - problem
« Reply #2 on: October 12, 2004, 05:58:31 pm »
Well, the compiler doesn't report any error (as the code is all right), however when I'm trying to read this string the program gives a message: "Invalid registry data type: ButtonFace". I've tried to see why this error occurs, and I tried code like that:
Code: [Select]
 Reg:=TRegistry.Create;
  Reg.RootKey:=HKEY_CURRENT_USER;
  Reg.OpenKey('Control Panel\Colors',True);
  if Reg.GetDataType('ButtonFace')=RdUnknown then ShowMessage('Unknown');
  if Reg.GetDataType('ButtonFace')=RdString then ShowMessage('String');
  if Reg.GetDataType('ButtonFace')=RdExpandString then ShowMessage('ExpandString');
  if Reg.GetDataType('ButtonFace')=RdInteger then ShowMessage('Integer');
  if Reg.GetDataType('ButtonFace')=RdBinary then ShowMessage('Binary');
  ShowMessage(IntToStr(Reg.GetDataSize('ButtonFace')));
  ShowMessage(Reg.ReadString('ButtonFace')+';'+IntToStr(Length(Reg.ReadString('ButtonFace'))));
  Reg.Free;

And it shows rdUnknown with Length=-1. Why? On Delphi the same code shows rdString with Length 11...

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
TRegistry and String Value - problem
« Reply #3 on: October 13, 2004, 10:56:26 am »
Was Reg.OpenKey able to open the key ?
(IOW, what is the function result ?)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
TRegistry and String Value - problem
« Reply #4 on: October 13, 2004, 02:33:18 pm »
Reg.OpenKey works properly. However GetDataType returns RdUnknown, when it should be RdString, GetDataSize returns -1, when it should be 11... And ReadString return a RunTime error...

 

TinyPortal © 2005-2018