Setting margins at runtime

FulcrumFulcrum Australia
edited 8:05AM in FastReport 2.xx VCL
Hi,

I have played with the labels demo file and I am getting the hang of everything.

I can adjust the number of columns and everything is working there.

My problem is setting the top margin. In the report designer I switched it to accept MM instead of pixels for all the measurements. At runtime in the PageHeaderBand OBP event I am setting the height of the band to equal a value passed in. That only sort of works.

It happily sets the top margin, but it seems to set it in pixels, not MM.

Is there a function to use to convert a MM value passed in as a variable into a pixel value?

The code I am currently using is this:
PageHeader1.Height := MyTopMargin;

If I pass in 50 it leaves about 20mm, if I pass in 100 it leaves about 40mm. That is what makes me think that it is ignoring my chosen value type and reverting to pixels.

Any help on this would be appreciated.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 8:05AM
    no there is not, all values for heights etc., are integer in pixels. default so you must calculate this yourself. and pass in the required value.
    ;)
  • gordkgordk St.Catherines On. Canada.
    edited 8:05AM
    I meant to add my own prefrenece is not to use a pageheader
    but to set top margin of designpage.
    less drift from rounding errors on long page runs.

    procedure TForm1.Button1Click(Sender: TObject);
    var
    // declare variables of these types
    v: TfrView;
    b: TfrBandView;

    Page: TfrPage;
    begin
    // you may want to set any of the tfrreport component's properties here.
    // if you want to change the default settings.
    frReport1.Pages.Clear; // clear any pages
    frReport1.Pages.Add; // create page of default type ptreport
    Page := frReport1.Pages[0]; // point page variable to 1st page of 0 based pages array

    Page.Prop := poportrait; // printers must be in uses clause
    page.UseMargins := true;
    page.pgMargins.Top := 50;// integer in pixels

    ;)
  • FulcrumFulcrum Australia
    edited 8:05AM
    Thanks for the replies.

    Is there any set function to use to calculate how many pixels to use? I presume there is as FastReports can use MM or inches throughout it.

    I don't want the user to have to guess too much in setting it up. I just want them to type in a value. I presume that the pixels per MM or inch could cary from system to system, or is there a simple constant value to use?

    Thanks again for any help in this.
  • FulcrumFulcrum Australia
    edited 8:05AM
    I may have just come up with my own answer. ;)

    If I read the width of the page (in pixels) from the report and I know the width in mm or inches, then I should be able to figure it out myself.

    The only glitch with this, without trying it, is that the PageWidth value returns a smaller page size that the actual page. I'll have to do some experimenting.

    I also need more than 2 hours sleep, but we can't have everything can we?

    ;)
  • gordkgordk St.Catherines On. Canada.
    edited 8:05AM
    when a page is first created fr picks up on the default page size of the default printer and the size is usually, IIRC, the printable area dimensions
    any how screen 800x600 is usually 96 pixels per inch.
    fr is not perfect wysiwig there is rounding errors.
    get some sleep things always look better with a clear head.
    ;)
  • I have just encountered same problem because I wanted to shift some memo fields for specified number of centimeters and needed some time to realize what have happened.

    I have solved it by putting blank memo field of size 1 x 1 cm, and then when I set dimensions at run time I just multiply desired dimension in centimeters with width/height of my Memo1cm.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.