Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - [VisualCLX] So was wie TApplication.Frames...?


Andreas Pfau - Mi 22.10.03 21:06
Titel: So was wie TApplication.Frames...?
Hallo,

gibt es irgendiwe die möglichkeit, um im Code durch alle Frames des Projekts zu "scrollen"? Um praktisch jedem Frame die Eigenschaft .Parent auf nil zu setzen? Ich mache das momentan so, dass ich für jeden Frame 'ne Zeile schreibe, aber geht das auch aüber 'ne Schleife, die automatisch alle Frames findet und abhakt?


Tino - Do 23.10.03 11:27

Kannst du nicht mit Hilfe der Eigenschaften ControlCount und Controls von der Form auf die Frames zugreifen?

Gruß
Tino


Andreas Pfau - Do 23.10.03 16:36

Hallo,

nein, habe ich grade ausprobiert - da kommen keine Frames.


Andreas Pfau - Do 23.10.03 21:16

Hallo,

dein Tipp war gar nicht so schlecht - habe mir das durch den Kopf gehen lassen, und bin auf folgenden Code gekommen:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  I: Integer;
begin
  for I := 0 to Application.ComponentCount - 1 do
    if (Application.Components[I] is TFrame) then
      (Application.Components[I] as TFrame).Parent := nil;

So funzts - die frames sind in den Komponenten der Anwendung aufgelistet!!!

Danke! :D


Tino - Fr 24.10.03 09:28

Hallo!

Finde ich ja komisch das man nicht auf die Frames durch die Eigenschaft Components der Form zugreifen kann.

Aber wenn es mit Application.Components geht... :-)

Gruß
Tino


Andreas Pfau - Fr 24.10.03 12:40

Hallo,

Ähhh... kann sein, ich habe nämlich die DPR ein bisschen "gemoddet":

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
program Morphium;

uses
  Forms,
  Controls,
  Morphium_MainForm in 'Morphium_MainForm.pas' {MainForm},
  Morphium_NewForm in 'Morphium_NewForm.pas' {NewForm},
  Morphium_ProjectFrame in 'Morphium_ProjectFrame.pas' {ProjectFrame: TFrame},
  Morphium_SetupFrame in 'Morphium_SetupFrame.pas' {SetupFrame: TFrame},
  Morphium_InfoFrame in 'Morphium_InfoFrame.pas' {InfoFrame: TFrame},
  Morphium_StartFrame in 'Morphium_StartFrame.pas' {StartFrame: TFrame},
  Morphium_InfoForm in 'Morphium_InfoForm.pas' {InfoForm},
  Morphium_PicturesFrame in 'Morphium_PicturesFrame.pas' {PicturesFrame: TFrame},
  Morphium_PictureFrame in 'Morphium_PictureFrame.pas' {PictureFrame: TFrame};

{$R *.RES}

begin
  // Anwendung initialisieren
  Application.Initialize;
  // Frames erzeugen
  Application.CreateForm(TProjectFrame, ProjectFrame);
  Application.CreateForm(TSetupFrame, SetupFrame);
  Application.CreateForm(TInfoFrame, InfoFrame);
  Application.CreateForm(TStartFrame, StartFrame);
  Application.CreateForm(TPicturesFrame, PicturesFrame);
  Application.CreateForm(TPictureFrame, PictureFrame);
  // Align auf Client setzen (Zur Entwurfszeit ist es einfacher,
  // mit alNone zu arbeiten)
  ProjectFrame.Align := alClient;
  SetupFrame.Align := alClient;
  InfoFrame.Align := alClient;
  StartFrame.Align := alClient;
  PicturesFrame.Align := alClient;
  PictureFrame.Align := alClient;
  // Formulare erzeugen
  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TNewForm, NewForm);
  Application.CreateForm(TInfoForm, InfoForm);
  // Anwendung starten
  Application.Run;
end.

Nicht wurdern - das ist keine "Drogensoftware", sondern ein Prog zum morphen von Bildern, daher der Name...

Normalerweise werden die frames nur explizit erzeugt, oder wenn ich zur Designzeit den Frame ins Form ziehe - ich mache es aber so, dann muss ich nämlich nur noch Parent zuweisen, und Zack - Frame sichtbar.