Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Enum Array in Delphi

I have enum type :

EPosition = (eLEFT, eRIGHT, eUP, eDOWN);

and EPosition array :

position: array[EPosition] of Integer;

Assign :

if (Key = VK_UP) then
  begin
    position[eTOP]:= 1;
  end;

  if (Key = VK_DOWN) then
  begin
    position[eDOWN]:= 1;
  end;

  if (Key = VK_LEFT) then
  begin
    position[eLEFT]:= 1;
  end;

  if (Key = VK_RIGHT) then
  begin
    position[eRIGHT]:= 1;
  end;

Then here is my error point :

for I := 0 to 3 do
    begin
      if obSubImage.PreviewROI.position[I] = 1 then
      begin
        obSubImage.RenderROI.width:= abs(oldNewDiff.X);
        obSubImage.RenderROI.height:= formMain.imgPreview.IEBitmap.Height;
        obSubImage.RenderROI.x:= obSubImage.PreviewROI.x;
        obSubImage.RenderROI.y:= obSubImage.PreviewROI.y;
        panOffsetX:= 0;
        panOffsetY:= 0;
        obSubImage.PreviewROI.position[I]:= 0;
        renderLayer(0);
      end;
    end;

It gives an incompatible types : 'EPosition' and 'Integer'. I know why it gives, i must write like;

    obSubImage.PreviewROI.position[eLEFT]:= 0;

But i don' t want to use IF-ELSE structure. I want to visit all index' s of array in LOOP. Is that possible?

like image 438
Dauezevy Avatar asked Apr 30 '26 05:04

Dauezevy


1 Answers

You have to use EPosition type variable in your loop.

Instead of i: integer use i: EPosition

for i := eLEFT to eDOWN do

or

for i := Low(EPosition) to High(EPosition) do
like image 124
Dalija Prasnikar Avatar answered May 02 '26 20:05

Dalija Prasnikar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!