Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Done BTM_Initialize and BTM_Terminate

Aug
2,831
149
When TCC starts, it looks for a TCStart.btm.
If found, it executes TCStart.btm (Initialize).

When TCC ends, it looks for a TCExit.btm.
If found, it executes TCExit.btm (Terminate).

I would like that ability with .BTM files.
Example;
Bash:
echo Before Init...
echo After Init...
echo Processing...
echo Before Exit...
echo After Exit...
quit

:BTM_Init
echo BTM_Init
Return

:BTM_Exit
echo BTM_Exit
Return

Output;
Bash:
BTM_Init
Before Init...
After Init...
Processing...
Before Exit...
After Exit...
BTM_Exit

Thus, the BTM_Init routine would be automatically executed,
if it exists in the .BTM file being executed,
before any code in the .BTM is executed.

The BTM_Exit routine would be automatically executed,
if it exists in the .BTM file being executed,
after the last line of code in the .BTM is executed.[/CODE]

I sometimes use this method in Harbour programming,
and I have VBScript and JScript classes that use this method;
Bash:
Class VFP9
  Private objVFP

  Private Sub Class_Initialize()
    Set objVFP = CreateObject("VisualFoxPro.Application.9")
  End Sub

  Public Function Eval(arg1)
    Eval = objVFP.Eval(arg1)
  End Function

  Function Version()
    Version = objVFP.Version
  End Function

  Private Sub class_Terminate()
    objVFP.Quit()
    Set objVFP = Nothing
  End Sub
End Class

Joe
 
Can't you do that with IF ISLABEL and GOSUB ... even wrap them in aliases?

Code:
alias btm_init `if islabel btm_init gosub btm_init`
alias btm_exit `if islabel btm_exit gosub btm_exit`

I suppose TCC could be given special aliases (like PRE_EXEC and friends).

Code:
v:\> type initexittest.btm
btm_init
btm_exit
quit

:btm_init
echo initializing ...
return

:btm_exit
echo finalizing ...
return

Code:
v:\> initexittest.btm
initializing ...
finalizing ...
 
Nope.

That still requires btm_init and btm_exit to be called from the .btm

I want btm_init (if it exists) and btm_exit (if it exists) to be called automatically upon execution/termination of the .btm

Here's how I do this using VBScript;
Bash:
Dim vfp
Set vfp = New VFP9
WScript.Echo vfp.Eval(365-111)
Set vfp = nothing

Class VFP9
  Private objVFP

  Private Sub Class_Initialize()
    Set objVFP = CreateObject("VisualFoxPro.Application.9")
  End Sub

  Public Function Eval(arg1)
    Eval = objVFP.Eval(arg1)
  End Function

  Function Version()
    Version = objVFP.Version
  End Function

  Private Sub class_Terminate()
    objVFP.Quit()
    Set objVFP = Nothing
  End Sub
End Class

No where is the code calling Class_Initialize(), or Class_Terminate()

Those two are called automatically,
upon creation and destruction of the Class.

They are not called by the program itself.

Joe
 
OK, I get it now. But making it automatic would only save you one line in the BTM ... worth the effort?

FWIW, this (far from robust) works in a plugin, but it's not automatic ... you have to call it.

Code:
INT WINAPI BTM_INIT(LPWSTR psz)
{
    WCHAR sz[64] = L"%@IF[islabel btm_init,gosub btm_init,]";
    ExpandVariables(sz, 0);
    Command(sz, 0);
    return 0;
}
 
Back
Top