BIG NEWS! I think that I may be almost there. I got rid of the duplicate identifiers, documents etc., uninstalled Lazarus 2.2.6,
removed all references to Utf8 and did some other stuff.
THE PROGRAM ALMOST COMPILES with only one error message holding things up. The error occurs in the code shown below and
in the attached screenshot.
The purpose of this code is to get the serial number of the monitor.
It appears to work fine on the old machine but not on the new machine.
Please look at it and see if you can tell what it needs or if you know another way to get the serial number.
Thank you. This bug is the only thing that prevents a successful compilation.
If this thing compiles then I will yell loudly, even if the neighbors complain and I will do a few other things too. My fingers are crossed.
function GetSerialNumber(var ASerial: WideString): Boolean;
const
FlagForwardOnly = $00000020;
WMIClass = 'Win32_PhysicalMedia';
WMIProperty = 'SerialNumber';
var
SWbemLocator, WMIService: Variant;
WbemObjectSet, WbemObject: Variant;
EnumVarinat: IEnumvariant;
SQL: WideString;
begin
Result := False;
SWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WMIService := SWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '');
SQL := WideString(Format('SELECT %s FROM %s', [WMIProperty, WMIClass]));
try
WbemObjectSet := WMIService.ExecQuery(SQL, 'WQL', FlagForwardOnly);
EnumVarinat := IUnknown(WbemObjectSet._NewEnum) as IEnumVariant;
if EnumVarinat.Next(1, WbemObject, nil) = 0 then
begin
if not VarIsNull(WbemObject.Properties_.Item(WMIProperty).Value) then
ASerial := WbemObject.Properties_.Item(WMIProperty).Value;
end;
WbemObject := Unassigned;
Result:= True;
except
on E: Exception do
ShowMessage('Cannot get serial number: ' + sLineBreak + E.Message);
end;
end;