Solved

Migrating to XE2

Posted on 2013-10-23
5
487 Views
Last Modified: 2013-10-28
Hi,


Migrationg to Xe2 from 2007 I am getting following error
Error=
      ERegistryException with message 'Invalid data type for 'SystemBIOSVersion'
Code Line=
      sl := ReadMultirowKey(RegistryV,'SystemBIOSVersion');

Regards
Allan


unit RegistryBIOS ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Registry, StdCtrls;

  function GetRegInfoWinNT(JobType:String):String ;
  function ReadMultirowKey(reg: TRegistry; Key: string): TStrings;

implementation

function GetRegInfoWinNT(JobType:String):String ;
var   // Usage  GetRegInfoWinNT('BIOSDate') or GetRegInfoWinNT('BIOSVersion')
  Registryv       : TRegistry;
  RegPath         : string;
  sl              : TStrings;
begin
  RegPath := '\HARDWARE\DESCRIPTION\System';
  registryv:=TRegistry.Create(KEY_QUERY_VALUE) ; // To overcome windows access rights.
  registryv.rootkey:=HKEY_LOCAL_MACHINE;
  sl := nil;
  try
    registryv.OpenKeyReadOnly(RegPath);
    if JobType='BIOSDate' then
      result:=RegistryV.ReadString('SystemBIOSDate')
    else if JobType='BIOSVersion' then
    begin
      sl := ReadMultirowKey(RegistryV,'SystemBIOSVersion');
      result:=sl.Text ;
    end;
  except
  end;
  Registryv.Free;
  if Assigned(sl) then sl.Free;
end;

function ReadMultirowKey(reg: TRegistry; Key: string): TStrings;
const 
  bufsize = 100;
var
  i: integer;
  s1: string;
  sl: TStringList;
  bin: array[1..bufsize] of char;
begin
  try
    result := nil;
    sl := nil;
    sl := TStringList.Create;
    if not Assigned(reg) then
      raise Exception.Create('TRegistry object not assigned.');
    FillChar(bin,bufsize,#0);
    reg.ReadBinaryData(Key,bin,bufsize);
    i := 1;
    s1 := '';
    while i < bufsize do
    begin
      if ord(bin[i]) >= 32 then
        s1 := s1 + bin[i]
      else
      begin
        if Length(s1) > 0 then
        begin
          sl.Add(s1);
          s1 := '';
        end;
      end;
      inc(i);
    end;
    result := sl;
  except
    sl.Free;
    raise;
  end;
end;


end.

Open in new window

0
Comment
Question by:Allan_Fernandes
  • 2
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39596878
Check if key values exists before do Read and check for data type too (if is compatible with ReadBinaryData)...
...
if reg.ValueExists(Key) then
    if reg.GetDataType(Key) = rdBinary then

Open in new window


... maybe value is of another type ....
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39596933
i'm guessing you get lots of warning about variable might not have been initialised ?

using the line
  var := nil
only takes away the warning, it doesn't actually solve the fault

your code reworked , with the fault removed
i had to change the 2nd function to a procedure

unit RegistryBIOS ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Registry, StdCtrls;

  function GetRegInfoWinNT(JobType:String):String ;
  procedure ReadMultirowKey(reg: TRegistry; Key: string; Data: TStrings);

implementation

function GetRegInfoWinNT(JobType:String):String ;
var   // Usage  GetRegInfoWinNT('BIOSDate') or GetRegInfoWinNT('BIOSVersion')
  Registryv       : TRegistry;
  RegPath         : string;
  sl              : TStrings;
begin
  RegPath := '\HARDWARE\DESCRIPTION\System';
  registryv:=TRegistry.Create(KEY_QUERY_VALUE) ; // To overcome windows access rights.
  try
    registryv.rootkey:=HKEY_LOCAL_MACHINE;
    registryv.OpenKeyReadOnly(RegPath);
    if JobType='BIOSDate' then
      result:=RegistryV.ReadString('SystemBIOSDate')
    else if JobType='BIOSVersion' then
    begin
      sl := TStringList.Create;
      try
        ReadMultirowKey(RegistryV,'SystemBIOSVersion', sl);
        result:=sl.Text ;
      finally
        sl.Free;
      end;
    end;
  finally
    Registryv.Free;
  end;
end;

procedure ReadMultirowKey(reg: TRegistry; Key: string; Data: TStrings);
const 
  bufsize = 100;
var
  i: integer;
  s1: string;
  bin: array[1..bufsize] of char;
begin
  if not Assigned(reg) then
    raise Exception.Create('TRegistry object not assigned.');
  if not Assigned(data) then 
    raise Exception.Create('Data variable not assigned');
  FillChar(bin,bufsize,#0);
  reg.ReadBinaryData(Key,bin,bufsize);
  i := 1;
  s1 := '';
  while i < bufsize do
  begin
    if ord(bin[i]) >= 32 then
      s1 := s1 + bin[i]
    else
    begin
      if Length(s1) > 0 then
      begin
        data.Add(s1);
        s1 := '';
      end;
    end;
    inc(i);
  end;
end;

end.

Open in new window

0
 

Author Comment

by:Allan_Fernandes
ID: 39599590
I appreciate the effort you are taking, but my problem was not resolved.
Later I found the solution at
http://www.swissdelphicenter.ch/torry/showcode.php?id=1431
0
 

Author Comment

by:Allan_Fernandes
ID: 39607860
I've requested that this question be closed as follows:

Accepted answer: 0 points for Allan_Fernandes's comment #a39599590

for the following reason:

-----
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39599633
ow,  that problem :)

i thought i'd resolve the code faults first, wait on your feedback and then proceed
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 90
QRReport  TQrmemo vertical stretching 1 46
URL for downloading Google Chrome for Win XP 2 157
MS Access from Delphi 31 30
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question