AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Objekte in verschiedenen Formularen zentral initialisieren

Objekte in verschiedenen Formularen zentral initialisieren

Ein Thema von Smiley · begonnen am 11. Jan 2025 · letzter Beitrag vom 12. Jan 2025
 
Kas Ob.

Registriert seit: 3. Sep 2023
412 Beiträge
 
#9

AW: Objekte in verschiedenen Formularen zentral initialisieren

  Alt 12. Jan 2025, 07:44
Well, if all your forms are already dpr created, meaning they are in the available forms in project options, then something like this should work
Delphi-Quellcode:
procedure TMainForm.FormCreate(Sender: TObject);
begin
  // These also could be adjusted and moved to initialization section
  FAlreadyActivated := False;

  // in case OnActivate is used in the project then it should be stored and restored later*
  Application.OnActivate := OnApplicationActivate;
end;

procedure TMainForm.OnApplicationActivate(Sender: TObject);
var
  C: Integer;
begin
  // ExitProc assigned in TApplication.Run meanning it could be used as indicator for done creating forms
  // can help in case Application.Activate wrongly (missused by) being called from a form constructor
  if not Assigned(ExitProc) then
    Exit;

  if not FAlreadyActivated then
  begin
    C := Application.ComponentCount;
    while C > 0 do
    begin
      Dec(C);
      if Application.Components[C] is TForm then
        // InitFormControls(Application.Components[C]);

    end;
  end;
  FAlreadyActivated := True;
  // here is later* ,( to restore original or more useful OnActivate)
end;
For runtime created forms and to minimize and centralize the code, use DDetours to hook TForm.Create then execute the original code followed by your InitFormControls after checking that the TForm is one of yours, if you would use DDetours then you don't any any code like the above.

https://github.com/MahdiSafsafi/DDetours
Kas
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz