IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

Gestion des Forms (fsMDIChild, fsnormal) etc


Sujet :

Delphi

  1. #1
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut Gestion des Forms (fsMDIChild, fsnormal) etc
    Bonjour à toutes et à tous...

    J'expose mon problème.

    J'ai 3 form
    Form1 : fsMDIForm
    Form2 : fsNormal
    Form3 : fsMDIChild

    Dans ma form1 j'ai un TMenu avec 2 menus et 1 item par menu

    Voilà exctement chaque .pas + le dpr :

    UNIT1

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;
     
    type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        Menu11: TMenuItem;
        Option11: TMenuItem;
        Menu21: TMenuItem;
        Option21: TMenuItem;
        procedure Option11Click(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure Option21Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    uses Unit2, Unit3;
     
    {$R *.dfm}
     
    procedure TForm1.Option11Click(Sender: TObject);
    begin
      Form2 := TForm2.Create(Application);
        Try
          Form2.ShowModal;
          Form2.Release;
        Finally
          Form2.free;
      end;
    end;
     
    procedure TForm1.FormActivate(Sender: TObject);
    begin
      WindowState := wsMaximized;
      Option11Click(Sender);
    end;
     
    procedure TForm1.Option21Click(Sender: TObject);
    begin
      With TForm3.Create(Self) do
      Begin
    //
      end;
    end;
     
    end.

    UNIT2

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    unit Unit2;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
     
    type
      TForm2 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      Form2: TForm2;
     
    implementation
     
    {$R *.dfm}
     
    end.
    UNIT3

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    unit Unit3;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
     
    type
      TForm3 = class(TForm)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      Form3: TForm3;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
    Action := cafree;
    end;
     
    end.

    DPR

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    program Project1;
     
    uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {Form2},
      Unit3 in 'Unit3.pas' {Form3};
     
    {$R *.res}
     
    begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
    //  Application.CreateForm(TForm2, Form2);
    //  Application.CreateForm(TForm3, Form3);
      Application.Run;
    end.
    Comme on peut le voir dans la form1, à l'activate de la form j'ouvre la form2.
    Et c'est là le probleme.
    Si on clique sur le Menu2 qui point sur l'ouverture de la form3 en fsMdichild puis on la ferme, alors il y a apparement l'exectution de la procédure ACTIVATE de la form1 donc il réalise l'ouverture de la form2, evidement elle n'apparait pas et si j'ouvre la form2 alors j'ai une mega erreur.

    En fait ce que je cherche.
    A l'ouverture de mon programme je dois ouvrir une fenetre pour donner un choix à l'user, cette fenetre sera egalement accessible depuis un item du menu principal.

    J'attends vos commentaires sur mon probleme et votre coup de main.

    Merci.

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 036
    Points : 40 941
    Points
    40 941
    Billets dans le blog
    62
    Par défaut
    Salut, ça faisait un bail

    Il me semble que si tu laisses Form2 se créer dans le dpr et que tu ne mettes rien dans le OnActivate ton problème sera résolu (du moins pour le début de programme).

    Ensuite , ne te restes qu'a gérer différemment l'appel de la Form2 via l'option du menu puisque TForm2 existe il suffit de faire (enfin je pense)
    Form2.Showmodal

    Bien sur , dans ce cas de figure Form2 est toujours en mémoire

    Mais je présume qu'en puriste (radin en mémoire) tu voudrais qu'elle disparaisse d'où le Release et Free ?

    (suite au prochain épisode )
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  3. #3
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Salut Serge, effectivement je suis sur un new programme. (j'aurais encore besoin de toi pour les impressions)

    Donc pour te répondre effectivement je ne souhaite pas laisser en mémoire la form3 ou la 2

    L'une est en fsnormal pour pas laisser l'user cliquer ailleur, l'autre en midichild pour pouvoir être libre dans le programme.

    @+

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 036
    Points : 40 941
    Points
    40 941
    Billets dans le blog
    62
    Par défaut
    Je m'en doutais,

    mais rien ne t'empêche de faire le free dans le DPR , en je pense a une fiche travaillant un peu comme un splashscreen (il y a de nombreux pot sur ce sujet je pense ).

    Je sais je suis un peu laconique mais également pressé

    @+
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  5. #5
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 421
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 421
    Points : 1 325
    Points
    1 325
    Par défaut
    Bonjour à toutes et à tous,

    @ BuzzLeclaire, j'avais fait ceci pour simuler un splash screen :

    DPR :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    program Spldemo;
     
    uses
      Forms,
      SPL in 'SPL.PAS' {Splform},
      Unit1 in 'Unit1.pas' {Form1};
     
    {$R *.res}
     
    begin
      Application.Initialize;
      // Affichage de l'écran Splash
      splform := TSplform.Create(application);
      try
         splform.Show;
         splform.DoFade(100);
         Application.CreateForm(TForm1, Form1);
      finally
             splform.Free;
      end;
      Application.Run;
    end.
    Fiche qui apparait en 1er avec un Timage (Splashimg) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
    unit SPL;
     
    interface
     
    uses
      Windows, Messages, SysUtils,  Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, jpeg;
     
    type
      TPercent = 0..100;
      TSplform = class(TForm)
        Splashimg: TImage;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormShow(Sender: TObject);
        procedure WMEraseBkgnd(var msg: TWMErasebkgnd); message WM_ERASEBKGND;
      private
        procedure Afterfade;
        { Private declarations }
      public
        { Public declarations }
        procedure DoFade(Duree: integer);
        procedure Wait(Duree: integer);
      end;
     
    var
      Splform: TSplform;
      scrbmp: TBitmap;
      mixbmp: TBitmap;
     
    procedure DrawTransparent(dstBitmap, srcBitmap: TBitmap; Transparency: TPercent);
    procedure GetScreenBitmap(r: TRect; var bitmap: TBitmap);
     
    implementation
     
    uses Unit1;
     
    procedure DrawTransparent(dstBitmap, srcBitmap: TBitmap; Transparency: TPercent);
    const
      MaxPixelCount = 32768;
    type
      PRGBTripleArray = ^TRGBTripleArray;
      TRGBTripleArray = array[0..MaxPixelCount] of TRGBTriple;
    var
      dstRow, srcRow: PRGBTripleArray;
      x, y: Integer;
    begin
      dstBitmap.PixelFormat := pf24bit;
      srcBitmap.PixelFormat := pf24bit;
      for y := 0 to srcBitmap.Height-1 do
      begin
        srcRow := srcBitmap.ScanLine[y];
        dstRow := dstBitmap.ScanLine[y];
        for x := 0 to srcBitmap.Width-1 do
        begin
          dstRow[x].rgbtRed := ((100-Transparency) * dstRow[X].rgbtRed) div 100 +
                                (Transparency * srcRow[X].rgbtRed) div 100;
          dstRow[x].rgbtGreen := ((100-Transparency) * dstRow[X].rgbtGreen) div 100 +
                                (Transparency * srcRow[X].rgbtGreen) div 100;
          dstRow[x].rgbtBlue := ((100-Transparency) * dstRow[X].rgbtBlue) div 100 +
                                (Transparency * srcRow[X].rgbtBlue) div 100;
        end;
      end;
    end;
     
    procedure GetScreenBitmap(r: TRect; var bitmap: TBitmap);
    var DC: HDC;
    begin
      Bitmap.Width := r.Right;
      Bitmap.Height := r.Bottom;
      DC := GetDC(0);
      try
        with Bitmap do
          BitBlt(Canvas.Handle, 0, 0,
                 Width, Height, DC, r.Left, r.Top, SrcCopy);
      finally
        ReleaseDC(0, DC);
      end;
    end;
     
    {$R *.dfm}
     
    procedure TSplform.FormCreate(Sender: TObject);
    begin
         Splashimg.Visible := false;
    end;
     
    procedure TSplform.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
         scrbmp.Free;
         mixbmp.Free;
    end;
     
    procedure TSplform.FormShow(Sender: TObject);
    begin
         with self do begin
              Splashimg.Width := Splashimg.Picture.Width;
              Splashimg.Height := Splashimg.Picture.Height;
              Width := Splashimg.Width;
              Height := Splashimg.Height;
              Left := round((Screen.Width)  / 2 - (Width  / 2));
              Top  := round((Screen.Height) / 2 - (Height / 2));
              self.FormStyle := fsStayOnTop;
         end;
    end;
     
    procedure TSplform.WMEraseBkgnd(var msg: TWMErasebkgnd);
    begin
         msg.Result := integer(false);
    end;
     
    procedure TSplform.DoFade(Duree: integer);
    var
       trans, delay: TPercent;
       i: integer;
    begin
         scrbmp := TBitmap.Create;
         mixbmp := TBitmap.Create;
         mixbmp.Assign(Splashimg.Picture.Bitmap);
         getscreenbitmap(rect(Left, Top, Width, Height), scrbmp);
         try
           delay := 0;
           for i := 1 to duree do begin
               trans := (i * 100) div duree;
               if trans <> delay then begin
                  Splashimg.Picture.Assign(mixbmp);
                  drawtransparent(Splashimg.Picture.Bitmap, scrbmp, (100-trans));
                  if not SplashImg.Visible then
                     Splashimg.Visible := true;
               end;
               delay := trans;
               application.ProcessMessages;
           end;
         finally
            mixbmp.Free;
            scrbmp.Free;
            Afterfade;
         end;
    end;
     
    procedure TSplform.Afterfade;
    begin
     
         wait(200);
    end;
     
    procedure TSplform.Wait(Duree: integer);
    var
       i: integer;
    begin
     
         for i := 1 to duree do begin
             application.ProcessMessages;
             sleep(1);
         end;
    end;
     
    end.
    Fiche principale :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
     
    type
      TForm1 = class(TForm)
        Label1: TLabel;
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    end.
    @+,

    Cincap

  6. #6
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Merci cincap.

    Mais cela ne correspond pas exactement à ce que je cherche.

    En fait dans l'histoire je ne savais pas qu'une forme qui est en fsMDIChild (ici form3) faisait un activate de la fsMdiForm à sa fermeture d'où mon problème.

    Ce que je cherche exactement.

    1) La form2 doit être accessible 1 fois au démarrage apres l'affichage de la form principal et est obligatoire d'oû le showmodal et sa propriété fsnormal
    2) Cette même form2 doit être accessible via un item du mes menus.
    3) Toutes les autres fiches sont en fsMDIChild.

    Si qulqu'un à une autre proposition je suis preneur. Pour corriger temporairement mon problème j'ai mis mis mon Option11Click(Sender); dans le show de la fiche principal au lieu du activate, mais évidement elle apparait en premier avant celle de la fiche principal.

    Merci à vous....

  7. #7
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    Passe par un événement asynchone.
    Je ne mets que l'unité 1, les autres sont sans intérêt

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;
     
    const
      WM_DISPLAYFORM2 = WM_USER;
     
    type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        Menu11: TMenuItem;
        Option11: TMenuItem;
        Menu21: TMenuItem;
        Option21: TMenuItem;
        procedure Option11Click(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure Option21Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      protected
        procedure WMDisplayForm2(var Message :TMessage); message WM_DISPLAYFORM2;
      public
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    uses Unit2, Unit3;
     
    {$R *.dfm}
     
    procedure TForm1.WMDisplayForm2(var Message :TMessage);
    begin
      with TForm2.Create(Application) do
      Try
        ShowModal;
      Finally
        free;
      end;
    end;
     
    procedure TForm1.Option11Click(Sender: TObject);
    begin
      //Affichage immédiat de la fiche 2
      Perform(WM_DISPLAYFORM2, 0, 0);
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      //Temporise l'affichage de la fiche 2
      PostMessage(Handle, WM_DISPLAYFORM2, 0, 0);
    end;
     
    procedure TForm1.FormActivate(Sender: TObject);
    begin
      WindowState := wsMaximized;
    end;
     
    ...
     
    end.
    Eventuellement dans le OnShow plutôt que le OnCreate. A toi de voir

  8. #8
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Hallucinant... je me demande où il arrive à nous pondre des trucs pareil....
    Je n'en attendais pas moins tu me diras...lol

    Pff il me tue ce AndnotOr ...

    Je vais tester cela de suite...

  9. #9
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Salut AndNotOr,

    Je viens de mettre en place dans mon programme.

    Mais j'ai un beau message d'erreur de violation avec des supers numéros.

    Alors j'ai exactement la même chose que toi.

    Juste pour préciser :
    Ma Form2 qui est en fsnormal, je l'ai retirer du DPR
    La formprincipal s'affiche bien
    j'ai retirer le activate, le show je ne joue que avec le Oncreate de la fiche principal.

    Voilà.

  10. #10
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    Je viens d'essayer et ça fonctionne parfaitement ! Ton erreur est ailleurs.
    N'aurais-tu pas une référence à Form1 depuis ta Form2 ?

    Form1 n'est pas encore assigné lors du passage dans OnCreate. Essaye OnShow pour voir. (Bien qu'au moment de la gestion du message il devrait l'être)

  11. #11
    Membre habitué Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Points : 179
    Points
    179
    Par défaut


    je te propose d'envoyer un message WM_FirstCall à la fin du OnCreate:
    On déclare WM_FirstCall puis la méthode procedure WMFirstCall(VAR aMsg:TMessage); MESSAGE WM_FirstCall;

    c'est une méthode que j'emploie régulierement.

    voici l'unité unit1:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;
     
    CONST   
           WM_FirstCall = WM_USER + 100;
     
     
    type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        Menu11: TMenuItem;
        Option11: TMenuItem;
        Menu21: TMenuItem;
        Option21: TMenuItem;
        procedure Option11Click(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure Option21Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
     
        procedure WMFirstCall(VAR aMsg:TMessage); MESSAGE WM_FirstCall;
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    uses Unit2, Unit3;
     
    {$R *.dfm}
     
    procedure TForm1.Option11Click(Sender: TObject);
    begin
         TForm2.Execute;
    end;
     
    procedure TForm1.FormActivate(Sender: TObject);
    begin
      WindowState := wsMaximized;
     
    end;
     
    procedure TForm1.Option21Click(Sender: TObject);
    begin
      With TForm3.Create(Self) do
      Begin
    //
      end;
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
          PostMessage(Handle,wm_FirstCall,0,0);
    end;
     
     
    procedure TForm1.WMFirstCall(var aMsg: TMessage);
    begin
         //
         TForm2.Execute;
    end;
     
     
    end.

    voici la form2:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    unit Unit2;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;
     
    type
      TForm2 = class(TForm)
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
     
      class procedure Execute;
      end;
     
    implementation
     
    {$R *.dfm}
     
     
    { TForm2 }
     
    class procedure TForm2.Execute;
              var
                 Form: TForm2;
    begin
         try
            Form:=TForm2.Create(Application);
            Form.ShowModal;
         finally
                FreeAndNil(Form);
     
         end;
     
    end;
     
    end.

    puis tu peut appeler ta form2 à partir d'une option du menu ou autre en faisant:


  12. #12
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Je viens d'essayer et ça fonctionne parfaitement ! Ton erreur est ailleurs.
    N'aurais-tu pas une référence à Form1 depuis ta Form2 ?

    Form1 n'est pas encore assigné lors du passage dans OnCreate. Essaye OnShow pour voir. (Bien qu'au moment de la gestion du message il devrait l'être)
    J'ai vider completement mon Oncreate de la form2 mais toujours pareil.

    Je cherche...

  13. #13
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    Sur quelle ligne tu as cette VA ?

  14. #14
    Membre éprouvé Avatar de BuzzLeclaire
    Homme Profil pro
    Dev/For/Vte/Ass
    Inscrit en
    Août 2008
    Messages
    1 606
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Dev/For/Vte/Ass

    Informations forums :
    Inscription : Août 2008
    Messages : 1 606
    Points : 1 113
    Points
    1 113
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Sur quelle ligne tu as cette VA ?
    celle-ci
    with FDossier.Create(Application) do
    enfin pour toi
    with TForm2.Create(Application) do

    MDRRRRRRRRRRRr, en copian ici à l'instant je viens de me rendre compte de ma bétise.

    j'ai écrit s
    with FDossier.Create(Application) do
    au lieu de
    with TFDossier.Create(Application) do

    Pfffff quel idiot.

    Dans le même temps j'ai testé cela fonctionne nikel chrome.

    Merci pour ta proposition neodelphi2007 qui se raproche de andnotor. toujours bon d'en avoir d'autre...


    PS AndNotOr : Je l'aurais un jour je l'aurais...

  15. #15
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    Vers l'infini Buzz... Vers l'infini !...


  16. #16
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    @ Neodelphi

    Just une petite info en passant
    Dans ta procédure de classe, évite de répéter le nom de la classe. Self pointe sur la classe de toute façon.
    Si une fois tu fais un héritage de ce type de fiche, ce sera la classe ancètre (TForm2) qui sera créée et non la classe héritée.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    class procedure TForm2.Execute;
    begin
      try
        with {Self.}Create(Application) do
          ShowModal;
      finally
        Free;
      end;
    end;

  17. #17
    Membre habitué Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Points : 179
    Points
    179
    Par défaut
    Tu a raison Andnotor

    Suite au prochain épisode... ;-)

    A++

    Didier

  18. #18
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 421
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 421
    Points : 1 325
    Points
    1 325
    Par défaut
    D6 et WinXP

    Bonjour à toutes et à tous,

    @ Neodelphi2007, j'ai testé le code d'AndNotOr et cela fonctionne correctement, j'ai recréé une application et indiqué ton code telquel, à la compilation j'ai l'erreur suivante :

    [Erreur] Unit1.pas(42): Identificateur non déclaré : 'Execute'
    [Erreur] Unit1.pas(57): Identificateur non déclaré : 'Execute'
    [Erreur] Unit1.pas(62): Pas assez de paramètres originaux
    [Erreur fatale] Project1.dpr(7): Impossible de compiler l'unité utilisée 'Unit1.pas'
    A cet endroit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    procedure TForm1.WMFirstCall(var aMsg: TMessage);
    begin
         //
         TForm2.Execute;
    end;
    Voici le code telquel :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    
    
    
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Menus;
    
     CONST
           WM_FirstCall = WM_USER + 100;
    
    type
      TForm1 = class(TForm)
        MainMenu1: TMainMenu;
        Menu11: TMenuItem;
        Option11: TMenuItem;
        Menu21: TMenuItem;
        Option21: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure FormActivate(Sender: TObject);
        procedure Option11Click(Sender: TObject);
        procedure Option21Click(Sender: TObject);
      private
        { Déclarations privées }
        procedure WMFirstCall(VAR aMsg:TMessage); MESSAGE WM_FirstCall;
      public
        { Déclarations publiques }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Unit2, Unit3;
    
    procedure TForm1.WMFirstCall(var aMsg: TMessage);
    begin
     
         TForm2.Execute; //A cet endroit
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      PostMessage(Handle,wm_FirstCall,0,0);
    end;
    
    procedure TForm1.FormActivate(Sender: TObject);
    begin
    WindowState := wsMaximized;
    end;
    
    procedure TForm1.Option11Click(Sender: TObject);
    begin
     TForm2.Execute;
    end;
    
    procedure TForm1.Option21Click(Sender: TObject);
    begin
      With TForm3.Create(Self) do
      Begin
    //
      end;
    end;
    
    end.
    As tu une explication ?

    Edit : Désolé, j'avais oublié de modifier TForm2, donc c'est OK

    Merci à vous deux.

    @+,

    Cincap

  19. #19
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 688
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 688
    Points : 13 117
    Points
    13 117
    Par défaut
    C'est que ta procédure Execute n'est pas public.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 26/01/2010, 15h49
  2. Gestion des forms en visual C++
    Par fpinter dans le forum C++/CLI
    Réponses: 6
    Dernier message: 21/01/2010, 21h56
  3. [MySQL] gestion des requetes MySQL, priorités , etc
    Par sebhm dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 07/08/2009, 09h18
  4. Réponses: 3
    Dernier message: 17/01/2008, 18h11
  5. [VB.NET]La bonne gestion des forms
    Par Wintermute dans le forum Windows Forms
    Réponses: 11
    Dernier message: 13/01/2004, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo