memo position on detail band
I wish to add some memo objects to detail band using code.
If I position the left,top etc or use setbounds is this position relative to the band or absolute to the page?
If absolute to the page how do I determine position.
If relative do I need to set bound height and width first
If I position the left,top etc or use setbounds is this position relative to the band or absolute to the page?
If absolute to the page how do I determine position.
If relative do I need to set bound height and width first
Comments
objects within the band a relative to the band.
you will probably wanto to set top, left width and height
also you will probably want to set a number of other properties of the memoview
ie dataset halign,memotext etc.
top would be 0 to align with the top of the band,
remember these properties are in pixels.
if not sure read the programmers manual on building reports from code.
Thanks for the response.
I was hoping locations are relative.
I have looked in the manual and tried adding sub bands to a master band at run time
however when I do this either all the memos are on top of each other (Indicating bands are on top of each other or the memos are winding up all on the master band).
or
The bands simply don't display.
I have tried child band and that worked but you can only do one of them.
I wish to add a number of bands below the master data using code at run time.
Each of which has a number of relative positioned memos containing report information.
I want them on the bands so the report will keep them together on a page rather than splitting if I put them all spread out on the master band.
Any suggestions?
Hint
make sure you have the designer in your app.
start with a small sample
load your saved report into the designer
frxreport1.loadfromfile('your filename.fr3');
add a memo to the band remember positions are in pixels.
if the memo is being placed at the top and left of the band, left is 0 top is 0.
now call designreport to see what you did and where you placed it.
frxreport1.designreport;
if you are happy with the result comment out the call to design report
and add your next object in code and call design report again.
repeat this process until you have a good idea of what you need to set when adding objects.
Have been trying this for a while, but will continue as you say.
If I add MasterData bands these work but each new set of memos is on a new page.
I wish to have the bands keep together if they will fit on one page so have tried both subreport and detail bands but they just all wind up on top of each other instead of following.
BTW you can add as many child bands as you want you siply chain them by setting the childband of the next child to the childproperty of the first child.
I now have the bands working correctly for the display but they don't export to PDF or RTF correctly every time.
I realised the position on the band is relative, but the band itself must have an absolute position.
I addressed this using
ReportData->SetBounds(0,ReportYpos, MasterData->Width, BandYpos);
Where ReportYPos is my accumulated position and BandYpos is the accumulated size for that band.
I load the initial report from a fr3 file which just has header band, single master band and footer band then add my new bands at run time.
Interesting thing is if I create the new masterdata band with the owner being the single MasterData band already on the form
ReportData = new TfrxMasterData(MasterData);
The page displays in the preview correctly but doesn't export to PDF, all I see is the Header and footer.
However if I create the band with the report page as the owner
ReportData = new TfrxMasterData(ReportPage);
Then the report won't show on the preview unless I set ReportData->RowCount = 1;
However when I export it to pdf or rtf sometimes it works, other times it just freezes and the disc grinds away continuously.
Not sure if this is embarcadero issue, testing further
when you load a report with some objects on it you must use the findobject method to be able to modify the object
so you need to declare variables of the correct type then use the findobject methodto find the object you wish to modify.
Bands are merely placeholders on a design page and only need to be in correct order (vertically) when they are dataheaders and datafooters. the report engine processes the bands from top down depending upon their band
type ie pgheader, dataheader, masterdata, datafooter, page footer.
the objects within the band are processed left to right in order of creation.
Read the chapter on creating a report from code.
C++:
int i, j;
TfrxMasterData * Band1;
TfrxDetailData * Band2;
TfrxMemoView * Memo;
Band1 = dynamic_cast <TfrxMasterData *> (frxReport1->FindObject("MasterData1"));
//now you can add objects to band1 here
Memo = new TfrxMemoView(Band1);
Memo->CreateUniqueName();
// connect to data
Memo->DataSet = frxDBDataset1;
Memo->DataField = "CustNo";
Memo->SetBounds(0, 0, 100, 20); // change your top and left to suit
Band2 = dynamic_cast <TfrxMasterData *> (frxReport1->FindObject("DetailData1"));
I am fine with adding memo objects to the existing bands in the report and also the finding the band within the report before adding the band.
What I am trying to do is add additional bands as I don't know how many bands I want at design time.
So I am trying to add additional bands at run time, but load from the file so I have a prepared header band and also prepared footer band.
If I cannot add bands at run time when the report has been loaded, I guess best option would be to generate a report template with more bands than I think I need and populate that way by locating the band I am up to and adding memos to that band.
But it means I have a template file with lots of bands for reports that only need 1.
C++:
TfrxReportPage * Page;
TfrxMasterData * DataBand;
Page = (TfrxReportPage *)frxReport1.Pages[1];
DataBand = new TfrxMasterData(Page);
DataBand->CreateUniqueName();
DataBand->DataSet = frxDBDataset1; //connect to dataset
// the Top coordinate should be greater than the previously added band???s top + height
DataBand->Top = 100;
DataBand->Height = 20;
That's what I am doing.
I found I needed to set the RowCount = 1 to make the memo's I added to display.
Here's basically what I am doing
ReportData = new TfrxMasterData(ReportPage);
if (ReportData)
{
ReportData->CreateUniqueName();
ReportData->StartNewPage = false;
ReportData->Stretched = true;
// Then I add the memo fields here
// BandYpos counts the height of these memos
// ReportYpos is the current position into the report page.
// Once all the memos are added I finalise the band as follows:
ReportData->SetBounds(0,ReportYpos, ReportPage->Width, BandYpos);
//Record the new position for the next band
ReportYpos += BandYpos;
// If I don't set the RowCount the band doesn't become visible, probably because I am only adding static memos rather than memos connected to the datasource
// For most reports I have a datasource and they generate fine, just have a couple I need to manually load Memo and Data
ReportData->RowCount = 1;
}
This is working reliably tonight, last night gave me issues when exporting to PDF (I think this was an Embarcadero IDE issue)
Thanks again for your help.
Now I just need to work out why RichView cannot do Courier New font on some PCs and I will be happy
page.
2 the reason you need to set the rowcount of the band is you have not set the band,datasetproperty
to connectit to data which will govern the nuber of rows printed.
3 make sure your designer is using large height in design mode and you are not using snap to grid.
this will give you more room to add your bands.
I don't know the final size I need till all memos are added, is it okay to make the band a bit bigger than my biggest and then set it to the actual size at the end?
It works, just want to make sure this is okay.
bear this in mind when working with memos and bands that stretch
when you have memos placed vertically one above the other
ie
memo1
memo2 stretching
memo3
memo4
it is better to place memo3&4 in a child band.
also note a single memo can contain more than 1 datafield vertically just use expressions and do not connectit to a datafield.