Página 1 de 1

fastreport tsqlquery solved

Publicado: Mié Mar 04, 2009 8:50 pm
por Ron Broere
Here is my solution to use fastreport with a xailer tsqlquery.
The functions SetXailerDataSet and GetSQLValue will pass a datasource to
fastreport.
I post it here, as a thank you for all the help you give me.
Ronald
//---------------------------------------------------------- --------------------
METHOD Button1Click( oSender ) CLASS TForm1
// this is an example sql query. make your own queries, as long as you give
every column an alias.
// in this example fastreport will receive a dataset with the alias:
HARDWARE and the fields: description, uren and day.
with object ::oSQLQuery1
IF :lOpen
:Close()
ENDIF
:cSelect := "SELECT billingTimeDurationEntries.durationDescription
description, " + ;
"billingTimeDurationEntries.hoursTotal uren, " + ;
"billingTimeDurationEntries.startDay day, " + ;
"FROM billingtimedurationentries WHERE etcetera etcetera ORDER
BY; "
:Open()
:GoTop()
END WITH
SetXailerDataSet( FrPrn, "HARDWARE" , ::oSQLQuery1 )
DoFrAction( "hardware.fr3" )
RETURN Nil
//---------------------------------------------------------- --------------------
function SetXailerDataSet(oFrManager, cFrAlias, oDataSet)
//---------------------------------------------------------- --------------------
local cStr:='', x, aVelden
for x := 1 to len( oDataSet:aFields)
cStr+=oDataSet:aFields[x]:cName + ";"
next
aVelden := oDataSet:aFields
oFrManager:SetUserDataSet(cFrAlias, cStr,;
{||oDataSet:GoTop}, {||oDataSet:Skip(1)}, ;
{||oDataSet:Skip(-1)}, {||oDataSet:Eof},;
{|cField| GetSQLValue( cField, oDataSet)})
Return Nil
//---------------------------------------------------------- --------------------
function GetSQLValue( cField, oDataSet)
local cRet := "", nPos, aVelden
// get the position of current fieldname in fields array
aVelden := oDataSet:aFields
nPos := ascan( aVelden,{|aVal| aVal:cName == cField})
// get the value
cRet := oDataSet:aFields[nPos]:Value
RETURN cRet