-1

I have to check for a sound card, so I don't need quality but only one answer yes or no. I used this code:

function IsSoundCardInstalled: Boolean;
Begin
   Result := waveOutGetNumDevs > 0;
End;

procedure TForm1.FormCreate(Sender: TObject);
var
  ids: TidIpWatch;
  Speed: Double;
  myStringList: TStringList;
begin
  ids := TidIpWatch.Create;
  Speed := GetCPUSpeed;
  ids.Free;

  myStringList:=TStringList.Create;
  myStringList.Add('IP:' + (ids.LocalIP));
  myStringList.Add('CPU: ' + (Tipo_cpu) + ' ' + Format('%f', [Speed]));
  myStringList.Add((IsSoundCardInstalled));
  myStringList.Add('etc.');

  Memo1.Lines.Assign(myStringList);

  myStringList.Free;
end;

But the error returns to me:

[DCC Error] Unit1.pas(138): E2010 Incompatible types: 'string' and 'Boolean'

On the line:

myStringList.Add((IsSoundCardInstalled));
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
MrCamarium
  • 5
  • 1
  • 5
  • You asked the exact same question two days ago. Literally the identical E2010 error! Are you going to ask about E2010 Incompatible types: 'string' and 'Integer' next? Please make more effort to understand the answer to your previous question. – David Heffernan Feb 10 '22 at 07:02

1 Answers1

0

IsSoundCardInstalled() returns a Boolean, but myStringList.Add() expects a string instead. You can't assign a Boolean as-is to a string, you need to use a conversion function (just like in your previous question), such as SysUtils.BoolToStr():

uses
  ..., SysUtils;

myStringList.Add(BoolToStr(IsSoundCardInstalled));

Or SysUtils.TBooleanHelper.ToString() in XE4+:

uses
  ..., SysUtils;

myStringList.Add(IsSoundCardInstalled.ToString);

On a side note: you are freeing the TIdIPWatch component before reading its LocalIP property, which is undefined behavior.

For that matter, you should not be using TIdIPWatch in this manner at all. It is meant for notifying you when the local IP changes, and for maintaining a history of local IP changes over time, but that is not how you have been using it lately. The TIdIPWatch.LocalIP property simply reads the global GStack.LocalAddress property, that is what you should be using instead:

uses
  ..., IdStack;

TIdStack.IncUsage;
try
  myStringList.Add('IP:' + GStack.LocalAddress);
finally
  TIdStack.DecUsage;
end;

However, a machine can have multiple local IPs, so you really should use GStack.GetLocalAddressList() instead:

uses
  ..., IdStack;

var
  myLocalIPList: TIdStackLocalAddressList;
  i: Integer;
begin
  ...
  TIdStack.IncUsage;
  try
    myLocalIPList := TIdStackLocalAddressList.Create;
    try
      GStack.GetLocalAddressList(myLocalIPList);
      for I := 0 to myLocalIPList.Count-1 do
        myStringList.Add('IP:' + myLocalIPList[I].IPAddress);
    finally
      list.Free;
    end;
  finally
    TIdStack.DecUsage;
  end;
  ...
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770