Solved

Migrating to XE2

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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