Trying to catch form creation

The project I'm working on consists of several 100 forms. They are mainly called from the main form. The application name is in all forms.

Now the other "version" of the application should have form signatures changed to a different application name. But this is conditional.

I came up with a binding

Screen.OnActiveFormChange := ScreenOnActiveFormChange;

in the form, create and follow the procedure for this.

procedure TFormMAIN.ScreenOnActiveFormChange(Sender: TObject);
begin
  if Newversion then begin
    if assigned(screen.activeform) then begin
      Screen.ActiveForm.Caption := SwapFormCaption(Screen.ActiveForm.Caption);
    end;
  end;
end;

This works well in 95% of cases. But in those 5%, the form is shown too quickly. The window is drawn before the title is updated and the windows remain there. But the signature already has a new meaning. That the patch worked increased and decreased the height of the form by 1 pixel, and then it showed correctly. form.repaint didn't help here. This is a pretty ugly way to do things.

. , .

+5
1

api?

SetWindowText(Screen.ActiveForm.Handle,PChar(SwapFormCaption(Screen.ActiveForm.Caption));

: : API DrawMenuBar

DrawMenuBar(Screen.ActiveForm.Handle);
0

All Articles