TfrxPictureView.Width doesn't work on runtime

edited 10:28PM in FastReport 4.0
Hi,

I have a TfrxPictureView component on a TfrxOverlay.
During runtime I set all necessary properties first and finally I load a JPG from a file to the Component.

[..]
logo := frxLayout.FindObject('Logo') as TfrxPictureView;
logo.AutoSize := False;
logo.Stretched := True;
logo.Top := logo_pos_top * fr1cm;
logo.Left := logo_pos_left * fr1cm;
logo.Width := logo_width * fr1cm;
logo.Picture.LoadFromFile(sfilename));
[..]

All properties work fine, but the property Width doesn??t. It keeps it size I defined during design time. Did I forget something?
Thanks for reply.

Michael

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited September 2010
    you have it in the wrong order: first you load it, then you set the width!
    Try this:
    logo := frxLayout.FindObject('Logo') as TfrxPictureView;
    logo.AutoSize := False;
    logo.Stretched := True;
    logo.Picture.LoadFromFile(sfilename));
    logo.Top := logo_pos_top * fr1cm;
    logo.Left := logo_pos_left * fr1cm;
    logo.Width := logo_width * fr1cm;
    


    Because LoadFromFile sets width/height internally, amongst other properties
  • edited 10:28PM
    Hi,

    I'm sorry but it doesn't work yet. Rather mysterious...

    Michael
  • gordkgordk St.Catherines On. Canada.
    edited 10:28PM
    works fine for me
    check the values for your variables don't forget values are in pixels.
    also check that you have not set any restriction flags
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 10:28PM
    Agreed, remove that Stretched = true, and any alignments.
    Well, better yet: delete your existing object in the designer, and put a new one, using the same name, without changing any property whatsoever
  • edited October 2010
    To demonstrate my problems I wrote some code. Easy to understand.
    My question: where is the mistake in the code of Button2?

    @Anu de deus
    Nothing happens if you remove Stretched := True;
    Thanks,
    Michael


    procedure TForm1.Button1Click(Sender: TObject);
    var
    frxlayout: TfrxReport;
    pg: TfrxReportPage;
    logo: TfrxPictureView;
    logo_orig_width, logo_orig_height: Word;
    logo_width, logo_top, logo_left: Extended;
    begin
    GetJPGSize('Logo.jpg', logo_orig_width, logo_orig_height); // in pixels
    // Instead of a function for getting the size of the JPG you want load to the
    // the TfrxPictureView, you can set the sizes manually.
    //logo_orig_width := ...; // pixels
    //logo_orig_height := ...; // pixels
    //
    // change width and position to see that it works fine
    logo_width := 10; // centimeters
    logo_left := 5; // centimeters
    logo_top := 5; // centimeters
    //
    frxlayout := TfrxReport.Create(nil);
    pg := TfrxReportPage.Create(frxlayout);
    pg.CreateUniqueName;
    pg.SetDefaults;
    try
    logo := TfrxPictureView.Create(pg);
    logo.Stretched := True;
    logo.AutoSize := False;
    logo.KeepAspectRatio := False;
    logo.Top := (logo_top * fr1cm); // centimeters to pixels
    logo.Left := (logo_left * fr1cm); // centimeters to pixels
    //
    logo.Picture.LoadFromFile('Logo.jpg');
    //
    logo.Width := (logo_width * fr1cm); // centimeters to pixels
    logo.Height := ((logo_width * (logo_orig_height / logo_orig_width)) * fr1cm); // centimeters to pixels
    //
    frxlayout.ShowReport();
    finally
    frxlayout.Free;
    end;
    end;


    procedure TForm1.Button2Click(Sender: TObject);
    // changing of property width doesn??t show any effect
    var
    frxlayout: TfrxReport;
    pg: TfrxReportPage;
    logo: TfrxPictureView;
    logo_width, logo_top, logo_left: Extended;
    begin
    logo_width := 10; // centimeters
    logo_left := 5; // centimeters
    logo_top := 5; // centimeters
    //
    frxlayout := TfrxReport.Create(nil);
    pg := TfrxReportPage.Create(frxlayout);
    pg.CreateUniqueName;
    pg.SetDefaults;
    try
    logo := TfrxPictureView.Create(pg);
    logo.Top := (logo_top * fr1cm); // centimeters to pixels
    logo.Left := (logo_left * fr1cm); // centimeters to pixels
    // without the following two lines you see nothing
    logo.Height := 100; // pixels
    logo.Width := 100; // pixels
    logo.AutoSize := False;
    logo.Stretched := True;
    logo.KeepAspectRatio := True;
    //
    logo.Picture.LoadFromFile('Logo.jpg');
    logo.Width := (logo_width * fr1cm); // centimeters to pixels
    //
    frxlayout.ShowReport();
    finally
    frxlayout.Free;
    end;
    end;
  • gordkgordk St.Catherines On. Canada.
    edited 10:28PM
    it does and so does your code
    begin
    logo_width := 10; // centimeters
    logo_left := 5; // centimeters
    logo_top := 5; // centimeters
    // theabove values are not centimeters they are just numerics

    fr1cm = 37.7953
    so logo_width * fr1cm = 377.953 pixels and that is what you are getting

    // without the following two lines you see nothing
    logo.Height := 100; // pixels
    logo.Width := 100; // pixels
    of course when you create the object you must give it some dimensions.
    you created the object with a width of 100 pixels
    you ended up with 377.953 pixels

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.