Page 1 of 1

AddArray

Posted: Wed Nov 19, 2014 2:53 am
by nbatocanin
I'm trying to add tables to report using AddArray method. This work fine, but i found one problem. When table is empty, then there is no data and method calling is:
oTest := oFr:AddArray ("Test", {}, aStruc)
This call does not add the table in the report. For example, this produces an error:
oTest:SetMaster (...)

AddArray

Posted: Wed Nov 19, 2014 12:10 pm
by ignacio
nbatocanin escribió el mié, 19 noviembre 2014 02:53
I'm trying to add tables to report using AddArray method. This work fine, but i found one problem. When table is empty, then there is no data and method calling is:
oTest := oFr:AddArray ("Test", {}, aStruc)
This call does not add the table in the report. For example, this produces an error:
oTest:SetMaster (...)

Obviously arrays should not be empty. But in any case you should get a valid oTest object. The sturcture of the array data should be equal to aStruc. So an empty array is not valid.
Regards,

AddArray

Posted: Wed Nov 19, 2014 1:43 pm
by nbatocanin
I think the object is _not_ valid. Please look at the following example:
#include "frh.ch"
PROC Main
oFr := FrReportManager():New()
oFr:Create()
f := {{"t_id", "N", 10, 0}}
a := {}
AAdd (a, {100})
AAdd (a, {200})
AAdd (a, {300})
oA1 := oFr:AddArray ("niz1", a, f)
b := {}
AAdd (b, {100}) // (*)
AAdd (b, {200}) // (*)
f := {{"t_id", "N", 10, 0}} // (**)
oA2 := oFr:AddArray ("niz2", b, f)
oA2:SetMaster (oA1, {"t_id=t_id"})
oFr:DesignReport()
oFr:End()
RETURN

This application works correctly. But, if you delete the (*) lines (table oA2 is empty), receives the error "SetMaster detail - Detail field t_id not found".
BTW, seems to AddArray has a bug. Check the value of F before and after the call AddArray:
before:
f := {{"t_id", "N", 10, 0}}
after:
f := {"t_id", "N", 10, 0}

AddArray

Posted: Wed Nov 19, 2014 2:30 pm
by ignacio
Dear Sir,
Cita:
This application works correctly. But, if you delete the (*) lines (table oA2 is empty), receives the error "SetMaster detail - Detail field t_id not found".

The bug arises because your array structure is not equal to your fields structure. So to say, you can not use empty arrays.
Cita:
after:
f := {"t_id", "N", 10, 0}

The property admits an array of arrays or an array of string with this structure: <name>,<type>,<len>,<dec>. If you use the first method then is converted to an array of string:
f := {"t_id,N, 10, 0"}
If you do not want that to happens send a aClone( f ). BTW, it will be fixed on next release.
Regards,

AddArray

Posted: Wed Nov 19, 2014 3:02 pm
by nbatocanin
ignacio wrote on Wed, 19 November 2014 14:30
Dear Sir,
Cita:
This application works correctly. But, if you delete the (*) lines (table oA2 is empty), receives the error "SetMaster detail - Detail field t_id not found".

The bug arises because your array structure is not equal to your fields structure. So to say, you can not use empty arrays.

I think it's a bit illogical, but ok. If I want to add a table via AddArray, I suppose I must add a "phantom empty record" when table is empty?