Lazarus

Programming => Packages and Libraries => LazReport => Topic started by: calebs on May 21, 2014, 12:23:23 am

Title: Master detail report help
Post by: calebs on May 21, 2014, 12:23:23 am
Hello all. I've trying to make a master/detail report with latest lazarus (1.2.2 now).
I've done another reports succesfully but never a master/detail.
I have in the form 2 memdataset with the data, 2 tfrdbdataset linked to each memdataset, and the tfreport objetc.
I've created the report, inserted the master data band with the fields in the master data, and a detail data band with his header.
The problem is when i open the report, it repeats the details for all the masters. I think that i miss the link field. I can't find that option anywhere so i think that calling with the same name and type a column in each dataset would suffice but it seems that not.
Any hint to achieve that?
Ps: I've opened the example in the components folder of lazreport but it's very cryptic for me and can't find anywhere the link (besides it uses dbf componentes and not memdatasets)

Thanks in advance
Title: Re: Master detail report help
Post by: ttomas on May 21, 2014, 12:46:22 am
You mast connect your datasets in master detail relationship.
Look for the DataSource property of your detail dataset.
First drop two dbgrids in your form and connect them to datasets to verify that you master/detail connection is working.
You can't use this concept with memdatasets. You can simulate with manuel seting of filters on details dataset.
Title: Re: Master detail report help
Post by: JanRoza on May 21, 2014, 07:42:11 am
@Ttomas: Calebs is talking about Lazreport, not about a form and dbgrids.
Title: Re: Master detail report help
Post by: ttomas on May 21, 2014, 03:40:13 pm
Yes me also.
Lazreport MasterData and DetailData band must be connected to Master/Detail connected DataSets with DataSource property.
First check that your master/detail relation is working with datasets, then try lazreport.
Title: Re: Master detail report help
Post by: JanRoza on May 21, 2014, 04:02:05 pm
Now I understand you. Yes, that's a good way to proceed.
Title: Re: Master detail report help
Post by: calebs on May 21, 2014, 04:47:41 pm
thanks thomas & janroza. I've using memdataset for storing tables because i didn't want to use any complex database storage for doing reports.
There is no way that i can use memdataset for this? Im using zeos with mysql for the general database in the program and the main databases are managed there.
Is there any other component that i can  use that relays on ram for this?
Title: Re: Master detail report help
Post by: ttomas on May 22, 2014, 12:04:33 am
As I said you can try with filter on detail dataset.
In AfterScroll event of master dataset you can set filter on detail dataset to simulate master/detail relation.
Another way is to use only one memdataset with all data (join) ordered by master fields and use GroupHeader band for master data and MasterData band for details data of the same memdataset.
Title: Re: Master detail report help
Post by: calebs on May 27, 2014, 12:09:39 am
Thanks thomas, i've started to find how the filter works but i found in several forums that the filter property doesn't works for memdataset, i can't find any clear source on how use the filter property. I think that it should be something like "id = 16' but doesn't worked, then read in some forums that filter doesn't work memdataset, but they work in bufdataset.
So dropped a couple of bufdataset on the form, created the fields in the fieldefs with the same fields i used on memdataset (double checked it), then linked it to the respective tfrbdataset in the form, but when i try to set active=true in bufdataset in the designer it gives me "Missing (compatible) underlying dataset can not open"
Title: Re: Master detail report help
Post by: BigChimp on May 27, 2014, 08:30:15 am
Thanks thomas, i've started to find how the filter works but i found in several forums that the filter property doesn't works for memdataset, i can't find any clear source on how use the filter property.
Correct, the filter property does not work; you could use onfilter at most:
http://wiki.lazarus.freepascal.org/How_to_write_in-memory_database_applications_in_Lazarus/FPC#Known_problems
Title: Re: Master detail report help
Post by: ttomas on May 27, 2014, 12:42:17 pm
Calebs, BufDataset have two editors for fields.
1. Drop TBufDataset on the form
2. Select and in ObjectInspector open FieldDefs editor and add your fields.
3. Select BufDataset and with Right mouse click in popup menu select Edit Fields..., then + Add Fields from FieldDefs.

Now you can set Active to True in designer.
In your case your FieldsDef is empty and you can't open dataset.
Title: Re: Master detail report help
Post by: calebs on May 27, 2014, 04:12:37 pm
thanks ttomas & bigchimp.
I've done that exactly ttomas in the same steps you told me but
when i'm on step 3, if i click on + it says:
"no es posible obtener la lista de campos del dataset
comprobar opciones del dataset
abstract method called" (hope you understand spanish)
I can use the third button (crear nuevo campo (create new field i think)) the one with the squared low dash.
There i can add 2 fields with the data type and it adds to the window.
But then, if i try to activate the  bufdataset it gives me the same error (missing (compatible) underlying...)
Title: Re: Master detail report help
Post by: calebs on May 27, 2014, 11:50:13 pm
I don't know if it helps, in the object inspector i have:
Code: [Select]
bufdataset1:tbufdataset
  <unknown collection> : tfieldefs
  0 - bufdataset1field3: tfieldef
  1 - bufdataset1field4: tfieldef

could be something to do with <unknown collection> ?
Title: Re: Master detail report help
Post by: calebs on June 13, 2014, 12:46:05 am
Well one time when i try to add dataset in designer fields appeared. Some others don't. And some other a GPF closed lazarus. It seems the component is buggy.
Finally i had to use mysql with zeos components for the report and 2 or 3 tables in database and used memory insted of innodb.
Sorry for the inconvenience, it seems i can't solve it using memdataset or other datasets.
Bye