SelectShapes Delphi Speed and Error

Hello,
I am trying to manipulate shapes…programatically using the OCX in Delphi 10 64Bits

After struggling with the boundaries a little bit, let me explain:
New(BB);
BB^ := Map1.Extents ;
BB^.SetBounds(Xg-2,Yg-2,0.0,Xg+2,Yg+2,0.0);

If I do not start the variable BB^ := Map1.Extents; and then modify it I get an exception error.

Anyway, coming around that problem… I am using:

var
Res : OleVAriant;
ResA : Array of Integer; //to be able to use Res

If sfwE.SelectShapes (BB^,1.0,INTERSECTION,Res) then Begin
if Sizeof(Res) > 0 then Begin
ResA := Res; //so I can use Low ang High for the array
sfwE.SelectNone;
for I := Low(ResA) to High(ResA) do Begin
sfwE.ShapeSelected [ResA[i]] := True;
End;
Map1.redraw;
End;
End;

This code works fine, but really takes a lot of time on bigger shape files.
My question is, what is the best way to optimize it.

Second Question.
When shapefile is line or polyline, eventually does not get the element and sometimes gives an error:
errorlines

I also discovered, that If I REBUILD (every time I change something) the code of my program, the performance is highly increased… But the exception on lines and polylines still appears more than 50 % of the times. What I want to say is that normally gives the exception, and eventually the line is selected properly…

Discovered something more interesting… Building in 32 bits works perfectly !!!
That is funny !!