How to catch an array index on a custom option

I am reading about TCustomVariantType and would like to know if there is a way to override the behavior when a variable like a custom variant is called with one or more array indices. If I quickly debug the DCU debugger on a[1]where ais the option, I see what _VarArrayGetis being called, but it is calling SafeArrayPtrOfIndexor SafeArrayGetElement, without being able to provide an alternative. I see that older versions have VariantManager, but this is deprecated. Is there a way to replace the pointer _VarArrayGet?

+4
source share
1 answer

How is the system connected, so that [x] ends as a call to VarArrayGet (a, [x])?

The compiler in modern versions of Delphi has created knowledge of the options and hard wires for the call VarArrayGet. Look at the code that the x86 compiler generates:

d := V[0];

converted to:

004234D7 6A00 push $ 00
004234D9 6A01 push $ 01
004234DB 6858AF4200 push $ 0042af58
004234E0 8D45C8 lea eax, [ebp- $ 38]
004234E3 50 push eax
004234E4 E81BD8FFFF call @VarArrayGet
004234E9 83C410 add esp, $ 10
004234EC 8D45C8 lea eax, [ebp- $ 38]
004234EF E864B8FFFF call @VarToReal
004234F4 DD1D68AF4200 fstp qword ptr [$ 0042af68]
004234FA 9B wait 

There is simply no extension point for you.

Your best option if you want to change behavior is to use a run-time code bypass.

0

All Articles