Solved

Migrating to XE2

Posted on 2013-10-23
5
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 27

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 38

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 38

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

617 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