Forum > LCL

Strange behavior of TGraphicControl objects inside a TScrollingWinControl

(1/2) > >>

simsee:
Inside a form I have a TScrollingWinControl which is the parent of a series of TGraphicControl objects, which are lines drawn on the canvas of the parent control, all created at run time.

I develop at office with a desktop computer and at home with a laptop. When I compile the latest version of the application code written on one of the two computers, and compile it on the other computer, the lines are not shown. At this point, if I enter in the IDE, press the F12 key, slightly resize the form editor with the mouse, then recompile the project, the lines are visible.

Difficult to provide the code, because it is quite large. Based on this summary description, do you have any plausible explanation for this strange phenomenon?

I'm on Microsoft Windows 10, with the latest release of Lazarus. Thank you.

simsee:
Comparing the .lfm files generated in the two machines (which have different versions of lazarus on board), in the first machine I have:

LCLVersion = '2.2.6.0'

while in the second:

LCLVersion = '2.2.0.4'.

Furthermore in the first I have

DesignTimePPI = 144

This setting is not present in the lfm file of the second machine.

In both machines, however, in the object inspector the DesignTimePPI property is set to 144.

wp:
When you save a form file the IDE writes the DesignTimePPI to the lfm file as a unit of measurement to define at which resolution the form was designed. It is like with kilometers and miles. When you say: "The distance between two towns to 10" the number has no meaning because it has no unit; only when you say "The distance is 10 miles" or "10 kilometers" it is clear.

Since the default setting for the screen resolution is 96ppi, however, the DesignTimePPI is not written when your system runs at this resolution. So, when you do not find a DesignTimePPI entry in the lfm file you know that the length dimensions are meant to be for 96ppi. Suppose your form contains an edit control which is 100 pixels wide. It will extend on the screen over approximately 1 inch. When you load this form on a system running at 192 ppi (and LCLscaling is activated in the project options) the IDE will notice that it will have to scale-up all lengths by a factor 2 and double the pixels for the edit's Width (still it will be 1 inch on the monitor because the monitor has twice pixel densitiy now). And when you save the form on that 192ppi system, the IDE will add the DesigntimePPI=192 line - and save the edit with Width 200.

simsee:
Thanks for the very thorough explanation. I had sensed that this was the problem, although without going to this depth.

What I don't understand is why in the object inspector, in both cases, the property is always 144.

The other question is: how to avoid this phenomenon? Disable LCLscaling?

wp:
What is the screen resolution for these two machines? To my knowledge the DesignTimePPI displayed in the object inspector is always the resolution of the current machine. When you open a 96ppi lfm file with a 144ppi compuler the length values in the file (which are for 96ppi) are automatically scaled to 144 ppi (i.e. multiplied by factor 1.5) so that the DesigntimePPI fo 144 is justified although the input file is for 96ppi.

Note that when you create controls at runtime you must take care of the scaling yourself. Suppose you create a button at runtime, with Left=10, Top=10, Width=100, Height = 100. The LCL will use these number at the current resolution, i.e. the button will be 100 pixels wide at all resolutions. But the other controls, created at designtime, will be scaled automatically to increase their size accordingly. You can imagine that this can cause trouble. If you want to scale the runtime-created button in the same way you should call one of the ScaleXXX functions of TControl:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    //scale support    function ScaleDesignToForm(const ASize: Integer): Integer;    function ScaleFormToDesign(const ASize: Integer): Integer;    function Scale96ToForm(const ASize: Integer): Integer;    function ScaleFormTo96(const ASize: Integer): Integer;    function Scale96ToFont(const ASize: Integer): Integer;    function ScaleFontTo96(const ASize: Integer): Integer;    function ScaleScreenToFont(const ASize: Integer): Integer;    function ScaleFontToScreen(const ASize: Integer): Integer;    function Scale96ToScreen(const ASize: Integer): Integer;    function ScaleScreenTo96(const ASize: Integer): Integer;
Scale96ToForm(x) means: x is understood as length for 96ppi; when the current system runs at a different resolution x will be multipied by the ratio of the current resolution to 96.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin  with TButton.Create(Self) do  begin    Parent := self;    { // not scaled    Left := 10;    Top := 10;    Width := 100;    Height := 100;    }    // scaled    Left := Scale96ToForm(10);    Top := Scale96ToForm(10);    Width := Scale96ToForm(100);    Height := Scale96ToForm(100);  end;end;
I don't know if this is related to the disappearing lines, though. It really would be helpful if you could provide a small sample project showing the issue.

Disappearing lines can occur also when they are not drawn in the paint cycle (OnPaint event). This has nothing to do with LCL scaling.

Navigation

[0] Message Index

[#] Next page

Go to full version