Solved

Migrating to XE2

Posted on 2013-10-23
5
503 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

756 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