Home > Mobile >  Can a routine know the unit where it runs?
Can a routine know the unit where it runs?

Time:10-04

Can a function/procedure know the unit/module where it runs (and maybe write it down to a text file)?
I know that there is a lot of debug info in the DCU/EXE file, including the association between the executable code and the source/pas code. Could it be accessed from inside the routine?

CodePudding user response:

Not a plain function or procedure, but a class knows the unit it is declared in. Therefore any method can get that from the UnitName class function.

You can make use of this even in a plain function or procedure in that unit, when you take any class declared in that unit and call TWhatEverClass.UnitName.

If there is no class declared in that unit you can declare one dummy class just for this purpose.

  • Related