Thank you guys for your kind of words !
I did not finished my started code in FMG_Editor with this new resources but I will try to explain to all of you.
We know for loading fmg file we use this:
Code: Select all
#include <hmg.ch>
Function Main
Load Window Main
Main.Center
Main.Activate
Return Nil
The main problem was this
Main given at Load, Center and Active the window MUST be the same name of fmg file and also MUST be compiled whit name already declared. And we want this name shall be variable name, because user needs to choose fmg file and NOT as fixed name.
So I made from begining with this basis idea and I prepared this example:
Code: Select all
/*
Demo0.prg to loading a form thru a string command
Author: Pablo César Arrascaeta
Date: Abril 24th, 2014
*/
#include <hmg.ch>
Function Main
DECLARE WINDOW Form_1
Exe_Fmg1()
Form_1.Center
Form_1.Activate
Return Nil
Function Exe_Fmg1()
DEFINE WINDOW Form_1 AT 138 , 235 WIDTH 550 HEIGHT 350 TITLE "Loading Manually" ICON NIL MAIN
END WINDOW
Return Nil
I saw that calling function can be DEFINE WINDOW normally but is needing been with form name already and WINDOWTYPE correctlly, in this case must be MAIN.
In my previous tests, I garantee to read fmg file line by line, because the fmg is text file type and assigned to array which it makes easier processing. So I take line by line and these lines should be treated in order to know:
- Rename TEMPLATES to <NewFormName>
- Add or correct the WindowType
- Concatenate multi-lines which could cointains ";" (line break characters) and let it as one command line.
I take each line and step by routine interpreting the sequence of commands (by
__PP_ Harbour functions) for the proper function according
i_window.ch. After this new string result I read and execute thru
hb_compileFromBuf and
hb_hrbDo from Harbour functions again.
By words, I know is hard to understand, so I make available an example to your understanding:
Code: Select all
/*
Demo1.prg for loading a form thru a string command at Runtime
Author: Pablo César Arrascaeta
Date: Abril 24th, 2014
*/
#include <hmg.ch>
REQUEST __PP_STDRULES
Function Main
DECLARE WINDOW Form_1
// Exe_Fmg1()
Exe_Fmg2()
Form_1.Center
Form_1.Activate
Return Nil
Function Exe_Fmg1()
DEFINE WINDOW Form_1 AT 138 , 235 WIDTH 550 HEIGHT 350 TITLE "" ICON NIL MAIN
END WINDOW
Return Nil
Function Exe_Fmg2()
Local cCommand, pPP
cCommand:='DEFINE WINDOW Form_1 AT 138 , 235 WIDTH 550 HEIGHT 350 TITLE "Stracted from FMG and putted manually" ICON NIL MAIN'
// pPP := __PP_INIT() // So it is not interpreted as HMG commands
pPP := __PP_INIT("C:\HMG.3.2\INCLUDE","i_window.ch") // Here we can regulize with function extracting HMG path
cResult:=__PP_Process( pPP, cCommand )
If !Empty(cResult)
Exe_Function(cResult)
Endif
cCommand:="END WINDOW"
cResult:=__PP_Process( pPP, cCommand )
If !Empty(cResult)
Exe_Function(cResult)
Endif
Return Nil
Function Exe_Function(cCommand)
Local cPrg := "Function Run_PP()" + CRLF + ;
cCommand + CRLF + ;
"Return Nil"
HRBCODE := hb_compileFromBuf( cPrg, "harbour", "-n", "-w3", "-es2", "-q0" )
HANDLE_HRB := hb_hrbload( HRBCODE )
hb_hrbDo( HANDLE_HRB )
hb_hrbunload( HANDLE_HRB )
Return Nil
So in this example, is still not reading from fmg file, but this is not the problem. The important is to be understood the procedures. You will see in source code above, a little complicated but it's working and was hard for me to find out. I made of this all alone... As far it is, I do not like to give up so easily and I wish to share with all of you.
From the beginning, I thought I was not the wiser way ... I suspected having to assemble various routines that could recognize each component. It was absurd, since it already existed within the HMG.
Now basically you can understand how it was done a dribble this question. Of course this routine is only to define the WINDOW and do miss to recognize the remaining components, but believe it will be very easy to do it too.
Now I want to continue to make it calmly and I want to ask to you my apologize for I had given the news and not post the code immediately. It is because my motivation to keep doing tests and let it ready as cleanest code, so I'll need more time.
Now I know I'm on the right track !
In view of what has already been discovered and explained, I think Rathi + Claudio, we can incorporated these functions for loading fmg files with a new option, something like this:
WINDOW LOAD FROM <fmgname> AS <alias_form_name> WINDOWTYPE <Main/Child/..>
And add to the
i_window.ch file to benefit everybody with over this feature. Of course, if this is approved by Roberto and the team of contributors HMG project.
What do you think ?