user3533628
user3533628

Reputation: 175

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 ?

Upvotes: 5

Views: 2411

Answers (2)

Sir Rufo
Sir Rufo

Reputation: 19116

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;

Upvotes: 15

David Heffernan
David Heffernan

Reputation: 613612

The for in loop syntax was introduced in Delphi 2005. Delphi 7 does not support this syntax. You'll need to re-code the loop to use a traditional index based for loop.

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

Upvotes: 2

Related Questions