How to correctly use _TRACE() inside <include.afl> files

Hello,

I use several #include statements to classify commonly-used functions. For example

#include <Test.afl>

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
priceColour = IIf( C >= Ref(C,-1), colorYellow, colorRed ); 
testFunction();
Plot( C, "Close", priceColour, GetPriceStyle() );

_SECTION_END();

where the included file has a test function with a simple _TRACE() statement

_SECTION_BEGIN("Test");
function testFunction()
{
  _TRACE("Entered test function");
}
_SECTION_END();

The logged statement uses the filename and line number of the included-from file, instead of the actual called filename and line number

Entered test function F:\AmiBroker AFL\AFL\Drag-drop\Price 11.afl 1 112 18:03:34.92

This logged line indicates line number 1 in the calling file from where the include file statement was invoked, and column number 112. Is there a way to log the actual filename and line number?

Is this the correct way to include AFL files?

Put this in your include file - it should show your file name

FN 	= StrExtract( StrExtract( GetFormulaPath(), -1, '\\' ), -2, '.' ) + ".afl";
_TRACE("Entered test function " + FN);

I wrote about it many times. #include is pre-processor command. Pre-processing as its name says occurs BEFORE execution and AFL parser sees the formula with everything already included. So at the moment when you execute your _TRACE there is simply no other file than just one currently executed. That is why you see main file name. It is by design.
So no amount of tricks would do, because the formula is pre-processed BEFORE execution.

Thanks for the replies.
@InStat_Research : Thanks for the tip!
@Tomasz : Ok, thanks for the explanation. I did search for #include before posting this message, but I didn't make the association about the consequences of #include pre-processing on the _TRACE() comand. This mean that _TRACE() doesn't display the correct line number inside #included files. Perhaps you need to add this to the on-line documentation.

You still do not understand. There is NO INCLUDE file at the time when formula is executed. There is JUST ONE formula and line number is reported CORRECTLY as entire included formula is virtually in the place where #include statement was.
And no @InStat_Reasearch "tip" does NOT work, because again, at the time when formula is executed there IS NO include file anymore. It is like entire content of #included file was copy-pasted IN SINGLE LINE where originally #include was.
All this happens BEFORE formula is executed.

The log shows the formula that is BEING EXECUTED, not some other formula.

1 Like

Thanks Tomascz,

Now I understamd :wink:
However, this all needs to be documented in two places
#include
_TRACE

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.