TfrxPictureView.Width doesn't work on runtime
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
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
Try this:
Because LoadFromFile sets width/height internally, amongst other properties
I'm sorry but it doesn't work yet. Rather mysterious...
Michael
check the values for your variables don't forget values are in pixels.
also check that you have not set any restriction flags
Well, better yet: delete your existing object in the designer, and put a new one, using the same name, without changing any property whatsoever
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;
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