Jump to content
Sign in to follow this  
dummzeuch

gem found in vcl.forms

Recommended Posts

I just found this code in vcl.forms in Delphi 10.2.3:

function ShouldScale(const self: TCustomForm): Boolean;
  // this is just to make code more readable
                                                                                  
begin
  Result := self.FScaled and not (csDesigning in self.ComponentState)
    and ((self.Owner = nil) or not (LowerCase(self.Owner.ClassName) = 'teditwindow'))  // we are not in an edit window
    and ((self.Parent = nil) or not (csDesigning in self.Parent.ComponentState) or not (csFreeNotification in self.Parent.ComponentState));
end;

What is this comparison with 'teditwindow' about? Looks as if somebody had to add this to make the IDE behave.

What if somebody's program uses a form called TEditWindow?

  • Haha 1
  • Sad 1

Share this post


Link to post
18 minutes ago, dummzeuch said:

What if somebody's program uses a form called TEditWindow?

... and makes that TEditWindow instance the owner of a to-be-scaled TCustomForm.

 

What bothers me more ist the csFreeNotification condition at the end. I mean, how is that related to scaling?

Share this post


Link to post
2 hours ago, Kas Ob. said:

LowerCase is more annoying :classic_huh:

More annoying is self.FScaled   :(   

 

Share this post


Link to post

This function exists also in 10.1, but for obvious reasons there is no trace of this code in Delphi XE. Somebody probably used some black magic to force scaling engine into the two decades old and pretty stable code of the Forms unit, but had to put duct tape here and there to make it work. No doubt that the IDE theming used even more glue and tape, that's why the themed IDE is a slow monster.

Share this post


Link to post

Its in 10.4.1.   Would adding csTheming csScaling switches be better?  csScalingDPIonly?  I just want the menubar font to change.

Share this post


Link to post
Guest

My scenary:

  • RAD Studio 10.3.3 Arch (Rio)
  • VLC project for test

 

in my observations I had:

  • the "teditwindow" just exist only one reference to this name/string in all (*.*) files from RAD Studio 10.3.3 Arch
    • only in "function ShouldScaled(...)", none any other file
  • as in "csDesigning" verification, for me, do sense verify "csFreeNotification" too!
    • as this action can be executed in many situations by many others actions, then, do sense, verify it.
  • as im expert, then, it's just my observation, not afirmation!

image.thumb.png.b7ef2074a1a5ae6f2e55d18971cfec52.png

 

source from RAD... called by "procedure TCustomForm.ScaleForCurrentDpi;"

function ShouldScale(const Self: TCustomForm): Boolean;
// this is just to make code more readable
var
  lSelfName            : string;
  lSelfFScaled         : Boolean;
  lSelfcsDesigning     : Boolean;
  lSelfOwner           : Boolean;
  lSelfOwnerName       : string;
  lSelfOwnerClassName  : string;
  lSelfParentName      : string;
  lSelfParentcsDesining: Boolean;
  lcsFreeNotification  : Boolean;
begin
  lSelfName             := '';      // ... very more readable yet!
  lSelfFScaled          := False;
  lSelfcsDesigning      := False;
  lSelfOwnerName        := '';
  lSelfOwner            := False;
  lSelfOwnerClassName   := '';
  lSelfParentName       := '';
  lSelfParentcsDesining := False;
  lcsFreeNotification   := False;
  //
  // "ToString" if "Name" empty
  if not(Self = nil) then
  begin
    lSelfName        := Self.ToString;                        { TfrmFormMain }
    lSelfFScaled     := Self.FScaled;                         { true }
    lSelfcsDesigning := (csDesigning in Self.ComponentState); { false = [csLoading]}
    //
    if not(Self.Owner = nil) then
    begin
      lSelfOwnerName      := Self.Owner.ToString;  { TAppliation }
      lSelfOwnerClassName := Self.Owner.ClassName; { TAppliation }
    end;
    //
    if not(Self.Parent = nil) then { = nil }
    begin
      lSelfParentName       := Self.Parent.ToString;
      lSelfParentcsDesining := (csDesigning in Self.Parent.ComponentState);
      lcsFreeNotification   := (csFreeNotification in Self.Parent.ComponentState);
    end;
  end;
  //
  // final resulted for a simple: create application with just one "TForm" and click F9 key to run with Debug
  //
  //           true         true         true  or    true          true       true          true
  //result := (True and not(False)) and (True or not(false)) and ((true or not(false)) or not(false))

  //csFreeNotification = One or more other components have requested that this component notify them when it is destroyed. This flag is set when another component calls this component's FreeNotification method.
  { So, if used extensively by many other actions, then it makes sense to check is "he" (the component / class) has not yet been released!
    Thus, how "csDesigning" is checked so that the component does not perform certain actions when it is not yet in a "runtime" environment!
  }
  //
  { in all code source of RAD 10.3.3 Arch, just exist "one reference to TEditWindow"... here!!!
  }
  //
  //
  // if "FormXXX.Scaled := False" is defined in Design-time == the function ShouldScaled will result = False, anyway!
  //
  Result := Self.FScaled and not(csDesigning in Self.ComponentState) and ((Self.Owner = nil) or not(LowerCase(Self.Owner.ClassName) = 'teditwindow')) // we are not in an edit window
    and ((Self.Parent = nil) or not(csDesigning in Self.Parent.ComponentState) or not(csFreeNotification in Self.Parent.ComponentState));
end;

 

my frmFormMain for test

implementation

{$R *.dfm}

procedure TfrmFormMain.FormCreate(Sender: TObject);
begin
  //
  // if defined in Design-time == the function ShouldScaled will result = False, anyway!
  // 
  Self.Scaled := false;  // occurr ... very very later than "function ShouldScale(const Self: TCustomForm): Boolean;"
end;

initialization

// if defined: (of course, the object not created yet)
// frmFormMain.Scaled := false; // "AV", in Vcl.Forms.pas, line: 5356 "procedure TCustomForm.SetScaled(Value: Boolean);"


finalization

end.

 

hug

Edited by Guest

Share this post


Link to post
23 minutes ago, emailx45 said:

as in "csDesigning" verification, for me, do sense verify "csFreeNotification" too!

  • as this action can be executed in many situations by many others actions, then, do sense, verify it.

 

Are your with that? The docs about csFreeNotification say:

Quote

One or more other components have requested that this component notify them when it is destroyed. This flag is set when another component calls this component's FreeNotification method.

That said, csFreeNotification is set when another component wants to be notified when the current component is destroyed. There is no specific action ongoing while csFreeNotification is set. In addition, csFreeNotification is only set but never unset.

Share this post


Link to post
Guest

the 

21 minutes ago, Uwe Raabe said:

Are your with that? The docs about csFreeNotification say:

That said, csFreeNotification is set when another component wants to be notified when the current component is destroyed. There is no specific action ongoing while csFreeNotification is set. In addition, csFreeNotification is only set but never unset.

  • the action was "already" executed! for sure, this "flag" is only for anyother "verify" if the object is alive!
    • then, do sense consult it, else, do not sense consult "csDesigning" or "csLoading"
  • if read all my code above, you would see my quote about "csFreeNotification" on HELP SYSTEM!
Edited by Guest

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×