I am having trouble in addeding buttons in execution time for a xbrowse Object and passing a function in a variable and using the "&".
When i click the button, i see a error message saying that the oBrw is not found.
Can someone help me on it?
Here is and exemple of the code
.
- Code: Select all Expand view RUN
#include "FiveWin.ch"
#include "xbrowse.ch"
#include "SQLRDD.ch"
//First at all, sorry for my poor inglish
//This code is a test function that i'm trying to implement in my sistem
//This take the position of the browse and the buttons that this will have and adjust in a Group
function main(cDSN) //this funcion is just for text
local dbRotG
connect(cDSN)
dbRotG :="Teste(oBrw)" //the function that i'll receive as a parameter
DEFINE WINDOW oWin FROM 1,1 TO 1024,1280 PIXEL TITLE "Teste" //PIXEL
SET MESSAGE OF oWin TO "Teste Window" CENTERED TIME DATE //Logozinho Rs
USE cadcli new via "sqlrdd"
DS_BROWSE(oWin,0,0,90,90,,dbRotG) //All as percent
ACTIVATE WINDOW oWin MAXIMIZED
return
//\\/\Testes/\//\\ upahead is the test function caller
****************************************************************************************************
function DS_Browse( oWin , vLeft , vTop , vWidth , vHeight , sTabela , bFunc )
local oBrw, oFra, oBtn, vBtnTop
vBtnTop=7 //the first button top
vX=(GetSysMetrics(0) / 100) ; vY=(GetSysMetrics(1) / 100) //Get the value of one percent of the window
if vLeft==nil ; vLeft=0 ; else ; vLeft*= vX ; endif //check the values
if vTop==nil ; vTop=0 ; else ; vTop *= vY ; endif //Checa se os dados são validos
if vWidth==nil ; vWidth=80 * vX ; else ; vWidth *= vX ; endif
if vHeight==nil ; vHeight=80 * vY ; else ; vHeight *= vY ; endif
if sTabela==nil ; sTabela=alias() ; endif //take the tables
oFra := desenharFrame(oWin,vLeft,vTop,vWidth,vHeight) //Desenha o Frame
oBrw := desenharBrowse(vWidth-(vX * 8.5), vHeight-(vY * 4),sTabela, oFra) //Desenha o Browse
if bFunc <> nil ; desenharBotao(vWidth-( vX*8) , vBtnTop, vX*8 , vY*3.3 , bFunc , oFra , oBrw) ; endif //Checa se uma outra variavel esta
//ok e então monta o botão
return
****************************************************************************************************
function desenharBrowse(vWidth,vHeight,sTabela, oFra)
local wfname, wfdesc
a='select * from campos where file_name = "' + (sTabela) + '" and SR_DELETED<>" " order by indkey_001'//field_ord, sr_recno'
use (A) alias campos new via "SQLRDD" //take the table listing the coluns we will use
go top
oBrw := TXbrowse():New( oFra ) //Options of the browse
oBrw:nMarqueeStyle := 5
oBrw:nColDividerStyle := LINESTYLE_DARKGRAY
oBrw:nRowDividerStyle := LINESTYLE_DARKGRAY
oBrw:lAllowRowSizing := .f.
oBrw:lAllowColHiding := .f.
oBrw:lAllowColSwapping := .f.
oBrw:LVScroll := .f.
oBrw:oFont :=TFont():New("Courier New") //The font
do while !eof() \\here the function will add colun one by oneof the tabla, but only the listed in the table campos
wfname = campos->field_name //The coluns
wfdesc = campos->field_desc
wflen = campos->field_len
sele (sTabela)
oCol := TXBrwColumn():New( oBrw )
oCol := oBrw:AddCol()
oCol:bStrData := { || &wfname }
oCol:nWidth := wflen * 10
oCol:cHeader := wfdesc
oCol:lAllowSizing=.f.
sele campos
skip
enddo
close
sele (sTabela)
oBrw:SetRDD() //i dont remember what is this now, i thing i just add this for test... rs
oBrw:CreateFromCode()
oBrw:nFreeze := 1
oBrw:nTop := 7
oBrw:nLeft := 0
oBrw:nHeight := vHeight
oBrw:nWidth := vWidth
//oBrw:VSetRange(1,1)
return oBrw
function desenharFrame(oWin, vLeft, vTop,vWidth,vHeight)
//Here the frame are maked
@ vTop-7 , vLeft GROUP oFra TO vTop+vHeight+7 , vLeft+vWidth PIXEL //Desenha o Frame
return oFra
****************************************************************************************************
function desenharBotao( vLeft , Vtop , vWidth , vHeight , bFunc , oFra, oBrw)
//Here is the case, i try do that of many ways
//bFunc := 'teste(oBrw)' i tryed use here many string inside of it and nothing
//bFunc := "{||teste(oBrw)}"
//bFunc := "{|oBrw|teste(oBrw)}"
@ vTop, vLeft BUTTON oBtn Prompt "Teste" of oFra ACTION Teste(oBrw) SIZE vWidth, vHeight PIXEL
//this is the only way i try and work. Butit is not what i want, i need pass the function reference in parameter
/* i try a lot o way, and no one work, here is some exemples of bads trys ;\
@ vTop, vLeft BUTTON oBtn PROMPT "Teste" of oFra ACTION &bFunc SIZE vWidth, vHeight PIXEL
@ vTop, vLeft BUTTON oBtn PROMPT "Teste" of oFra ACTION bFunc SIZE vWidth, vHeight PIXEL
@ vTop, vLeft BUTTON oBtn PROMPT "Teste" of oFra ACTION {||&bFunc} SIZE vWidth, vHeight PIXEL
@ vTop, vLeft BUTTON oBtn PROMPT "Teste" of oFra ACTION {|oBrw|&bFunc} SIZE vWidth, vHeight PIXEL
btnNew := TButton():New(vTop,vLeft,"&New",oFra,,vWidth,vHeight,,,.F.,.T.,.F.,,.F.,,,.F. )
oBtn:bAction = {||&bFunc}
oBtn:bAction = bFunc
oBtn:bAction = {|oBrw|&bFunc}
*/
/* this don't work :@
@ vTop, vLeft BUTTON oBtn PROMPT "Teste" OF oFra SIZE vWidth, vHeight PIXEL
oBtn:bAction = { || &bFunc}//,oBrw:GoBottom(), oBrw:SetFocus() }
*/
return
****************************************************************************************************
function Teste(oBrw)
msginfo(oBrw:nHeight) //just do see if the function can access the browse
return obj
****************************************************************************************************
#include "d:\xhb\samples\sqlrdd\connect.prg" //the SQLRDD conection (Must have a ini file on the app path with the conection string
I dont know very well FiveWin, if some one know other way to do that, i'll be happy to know
Thanks for all.