Alternatives to For..in loop in Delphi 7?

I get 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): the operator is not applicable to this type of operand

Any alternative way? or how can i fix it?

+4
source share
2 answers

Delphi 7 does not support for .. in, so you have to iterate over the array TSMBios.ProcessorInfoyourself

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;
+14
source

The for in loop syntax was introduced in Delphi 2005. Delphi 7 does not support this syntax. You will need to recode the loop to use the traditional loop-based index.

for i := 0 to high( SMBios.ProcessorInfo ) do
begin
  LProcessorInfo := SMBios.ProcessorInfo[i];
  ....
end;
+2
source

Source: https://habr.com/ru/post/1541066/


All Articles