Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives for For..in loop in Delphi 7?

I'm getting an error with Delphi 7 on for in loop when compiling this code Link

procedure GetProcessorInfo;
Var
  SMBios             : TSMBios;
  LProcessorInfo     : TProcessorInformation;
  LSRAMTypes         : TCacheSRAMTypes;
begin
  SMBios:=TSMBios.Create;
  try
      WriteLn('Processor Information');
      if SMBios.HasProcessorInfo then
      for LProcessorInfo in SMBios.ProcessorInfo do // <-- Error here
      begin
        ...
      end;
  ...
end;

Error message:

[Error] Project1.dpr(52): Operator not applicable to this operand type

Any alternative way ? or how can I fix it ?

like image 910
user3533628 Avatar asked Dec 05 '22 06:12

user3533628


1 Answers

Delphi 7 does not support for .. in, so you have to iterate the TSMBios.ProcessorInfo array by yourself

procedure GetProcessorInfo;
Var
  SMBios             : TSMBios;
  LProcessorInfo     : TProcessorInformation;
  LSRAMTypes         : TCacheSRAMTypes;
  LIdx : Integer; // add this
begin
  SMBios:=TSMBios.Create;
  try
    WriteLn('Processor Information');
    if SMBios.HasProcessorInfo then
      // for LProcessorInfo in SMBios.ProcessorInfo do
      for LIdx := Low( SMBios.ProcessorInfo ) to High( SMBios.ProcessorInfo ) do
      begin
        LProcessorInfo := SMBios.ProcessorInfo[LIdx];
        ...
      end;
  ...
end;
like image 186
Sir Rufo Avatar answered Dec 31 '22 23:12

Sir Rufo