Wednesday, September 30, 2015

Access the SMBIOS using Object Pascal (Delphi, FPC) https://theroadtodelphi.wordpress.com/

The SMBIOS (System Management BIOS) is a standard developed by the DMTF. The information stored in the SMBIOS includes devices manufacturer, model name, serial number, BIOS version, asset tag, processors, ports and device memory installed.
logoThe TSMBIOS project allows access the System Management BIOS (SMBIOS) using the Object Pascal language (Delphi or Free Pascal).

Features

Some features of this project are
  • Source Full documented compatible with the help insight feature, available since Delphi 2005.
  • Supports SMBIOS Version from 2.1 to 2.8
  • Supports Delphi 5, 6, 7, 2005, BDS/Turbo 2006 and RAD Studio 2007, 2009, 2010, XE, XE2, XE3, XE4, XE5, XE6, XE7, XE8, 10 Seattle.
  • Compatible with FPC 2.4.0+
  • Supports Windows, Linux (only using FPC)
  • SMBIOS Data can be obtained using WinAPI (Only Windows), WMI (Only Windows) or loading a saved SMBIOS dump
  • SMBIOS Data can be saved and load to a file
  • SMBIOS Data can be obtained from remote machines

SMBIOS Tables supported

Sample source code

This code shows how you can retrieve the information related to the memory device installed on the system.
{$APPTYPE CONSOLE}

{$R *.res}

uses
  Classes,
  SysUtils,
  uSMBIOS in '..\..\Common\uSMBIOS.pas';

procedure GetMemoryDeviceInfo;
Var
  SMBios : TSMBios;
  LMemoryDevice  : TMemoryDeviceInformation;
begin
  SMBios:=TSMBios.Create;
  try
      WriteLn('Memory Device Information');
      WriteLn('-------------------------');

      if SMBios.HasPhysicalMemoryArrayInfo then
      for LMemoryDevice in SMBios.MemoryDeviceInformation do
      begin
        WriteLn(Format('Total Width    %d bits',[LMemoryDevice.RAWMemoryDeviceInfo.TotalWidth]));
        WriteLn(Format('Data Width     %d bits',[LMemoryDevice.RAWMemoryDeviceInfo.DataWidth]));
        WriteLn(Format('Size           %d Mbytes',[LMemoryDevice.GetSize]));
        WriteLn(Format('Form Factor    %s',[LMemoryDevice.GetFormFactor]));
        WriteLn(Format('Device Locator %s',[LMemoryDevice.GetDeviceLocatorStr]));
        WriteLn(Format('Bank Locator   %s',[LMemoryDevice.GetBankLocatorStr]));
        WriteLn(Format('Memory Type    %s',[LMemoryDevice.GetMemoryTypeStr]));
        WriteLn(Format('Speed          %d MHz',[LMemoryDevice.RAWMemoryDeviceInfo.Speed]));
        WriteLn(Format('Manufacturer   %s',[LMemoryDevice.ManufacturerStr]));
        WriteLn(Format('Serial Number  %s',[LMemoryDevice.SerialNumberStr]));
        WriteLn(Format('Asset Tag      %s',[LMemoryDevice.AssetTagStr]));
        WriteLn(Format('Part Number    %s',[LMemoryDevice.PartNumberStr]));

        WriteLn;

        if LMemoryDevice.RAWMemoryDeviceInfo.PhysicalMemoryArrayHandle>0 then
        begin
          WriteLn('  Physical Memory Array');
          WriteLn('  ---------------------');
          WriteLn('  Location         '+LMemoryDevice.PhysicalMemoryArray.GetLocationStr);
          WriteLn('  Use              '+LMemoryDevice.PhysicalMemoryArray.GetUseStr);
          WriteLn('  Error Correction '+LMemoryDevice.PhysicalMemoryArray.GetErrorCorrectionStr);
          if LMemoryDevice.PhysicalMemoryArray.RAWPhysicalMemoryArrayInformation.MaximumCapacity<>$80000000 then
            WriteLn(Format('  Maximum Capacity %d Kb',[LMemoryDevice.PhysicalMemoryArray.RAWPhysicalMemoryArrayInformation.MaximumCapacity]))
          else
            WriteLn(Format('  Maximum Capacity %d bytes',[LMemoryDevice.PhysicalMemoryArray.RAWPhysicalMemoryArrayInformation.ExtendedMaximumCapacity]));

          WriteLn(Format('  Memory devices   %d',[LMemoryDevice.PhysicalMemoryArray.RAWPhysicalMemoryArrayInformation.NumberofMemoryDevices]));
        end;
        WriteLn;
      end
      else
      Writeln('No Memory Device Info was found');
  finally
   SMBios.Free;
  end;
end;


begin
 try
    GetMemoryDeviceInfo;
 except
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.

Help Insight https://github.com/rruz/tsmbios

Help Insight

Monday, September 28, 2015

when radio button is selected, a popup box should display the text of the radio button

<script type="text/javascript">
function radioEvent(form) 
{
 for (var i = 0; i < form.radioButton.length; i++) 
 {
    if (form.radioButton[i].checked)
    {
        alert("You chose " + form.radioButton[i].value + ".")
    }
 }
 }
</script>
</head>
<body>
<form>
<input type="radio" name= "radioButton" value= "Excellent"   onclick="radioEvent(this.form);"/> Excellent<br/>
<input type="radio" name="radioButton"  value="Very Good" onclick="radioEvent(this.form);"/> Very Good <br/>
<input type="radio" name="radioButton"  value="Good" onclick="radioEvent(this.form);"/> Good <br/>
<input type="radio" name="radioButton"  value="Satisfactory" onclick="radioEvent(this.form);"/> Satisfactory
</form>
</body>
</html>
shareimprove this answer
   
Thank you for the above code.Is it the same procedure for drop-down box, check box and text input too? – Navya Akkiraju Oct 13 '12 at 23:14 
   
yes, just change type of Input tag –  vinus patel Oct 15 '12 at 1:43

PHP Notice: Undefined offset: 1 with array when reading data


I am getting this PHP error:
PHP Notice:  Undefined offset: 1
Here is the PHP code that throws it:
$file_handle = fopen($path."/Summary/data.txt","r"); //open text file
$data = array(); // create new array map

while (!feof($file_handle) ) {
    $line_of_text = fgets($file_handle); // read in each line
    $parts = array_map('trim', explode(':', $line_of_text, 2)); 
    // separates line_of_text by ':' trim strings for extra space
    $data[$parts[0]] = $parts[1]; 
    // map the resulting parts into array 
    //$results('NAME_BEFORE_:') = VALUE_AFTER_:
}
What does this error mean? What causes this error?
shareimprove this question
1 
How sure are you that every line in your file has a colon in it? –  andrewsi Jul 3 '13 at 19:16
   
do a var_dump($parts). you'll probably find that the point you get that undefined offset, there is no 1key in the parts array. –  Marc B Jul 3 '13 at 19:16
2 
If it looks like all the lines have a colon, check for blank lines. –  Barmar Jul 3 '13 at 19:18
   
you just need to make sure that count($parts) == 2 prior to doing your assignment. –  Orangepill Jul 3 '13 at 19:18 
   
@Orangepill You mean count($parts). –  Barmar Jul 3 '13 at 19:18

3 Answers

up vote28down voteaccepted
change
$data[$parts[0]] = $parts[1];
to
if ( ! isset($parts[1])) {
   $parts[1] = null;
}

$data[$parts[0]] = $parts[1];
or simply:
$data[$parts[0]] = isset($parts[1]) ? $parts[1] : null;
Not every line of your file has a colon in it and therefore explode on it returns an array of size 1.
According to php.net possible return values from explode:
"Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter."
"If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned."
shareimprove this http://stackoverflow.com/questions/17456325/php-notice-undefined-offset-1-with-array-when-reading-dataanswer