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 :

fonction impossible sur form créée a la volée :s


Sujet :

Delphi

  1. #1
    Membre habitué Avatar de avogadro
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    412
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 412
    Points : 188
    Points
    188
    Par défaut fonction impossible sur form créée a la volée :s
    Bonjour,
    En fait j'utilise ce code :

    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
    var
        my_picture : TImage; 
        photo : string; 
    begin 
         my_form := TForm.Create(self);
         my_picture := TImage.Create(my_form);
         with my_picture do 
              begin 
                   photo := Application.GetNamePath + 'vnp1.jpg'; 
              if FileExists(photo) then 
                begin
                   my_picture.Picture.LoadFromFile(photo);
                   Align := alclient;
                   my_form.height := my_picture.picture.height;
                   my_form.width := my_picture.picture.width;
                   parent := My_form;
                   Visible := true;
                   Onclick := close;
                end 
              else ShowMessage('La photo est introuvable'); 
              end;
         with my_form do
              begin
                   BorderStyle := bsNone;
                   Position := poScreenCenter;
                   Visible := true;
                   // ou ici : Onclick := close;               
              end;
    end;
    mais la ligne
    ne fonctionne pas, de meme si je souhaite avoir les paramètre du dragover de l'image1 sur cette my_picture, est ce que avec un code comme celui ci ça serait possible??
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    OnDragOver := Image1.OnDragOver;
    merci pour votre aide !
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=
    (\_/)
    (O.o)
    (> <)
    This is Bunny. Copy Bunny into your signature to help him on his way to world domination!!
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=

  2. #2
    Membre confirmé
    Avatar de Philippe Gormand
    Inscrit en
    Mars 2002
    Messages
    330
    Détails du profil
    Informations forums :
    Inscription : Mars 2002
    Messages : 330
    Points : 647
    Points
    647
    Par défaut OnClose ?
    Bonjour.

    Dans ton exemple, tu utilise une fiche créé de façon dynamique et libre.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    var 
        my_picture : TImage; 
        photo : string; 
    begin 
         my_form := TForm.Create(self);
    Elle n'apartient pas à l'application.

    Tu doit fermer la fiche en la détruisant.

    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
     
     
    var 
        my_picture : TImage; 
        photo : string; 
    begin 
         my_form := TForm.Create(self); 
         my_picture := TImage.Create(my_form); 
         with my_picture do 
              begin 
                   photo := Application.GetNamePath + 'vnp1.jpg'; 
              if FileExists(photo) then 
                begin 
                   my_picture.Picture.LoadFromFile(photo); 
                   Align := alclient; 
                   my_form.height := my_picture.picture.height; 
                   my_form.width := my_picture.picture.width; 
                   parent := My_form; 
                   Visible := true; 
                   Onclick := close; 
                end 
              else ShowMessage('La photo est introuvable'); 
              end; 
         with my_form do 
              begin 
                   BorderStyle := bsNone; 
                   Position := poScreenCenter; 
                   Visible := true; 
                   // ou ici : Onclick := close;                
              end; 
        my_form.Release; // détruit la fiche avec tout ce qu'elle contient
    end;
    Mais je suppose que ce n'ai pas ce que tu veux faire.

    Si tu veux la gérer comme une autre fiche appartenant à l'application, il
    faut la déclarer de façon globale avec TApplication comme parent.

    Quelque part dans ton code, pour créer la fiche il faut écrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
      my_form := TForm.Create(Application);
    Ne pas oublier de la détruire à la fin du programme avec la méthode Release.

    Tu devrais trouver un tutorial sur le site Developpez.com je pense.
    Si non, cherche sur le WEB. Je ne peux pas t'en dire plus, n'ayant pas
    le source de ton programme.

    Bon courage.
    Rien n'est moins sur que l'incertain : Pierre DAC

  3. #3
    Membre habitué Avatar de avogadro
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    412
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 412
    Points : 188
    Points
    188
    Par défaut
    j'ai deja placé un code similaire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my_form := TForm.Create(self);
    en fait le coup du realease est bien ce qu'il me faudrait, mais il faut que je trouve le moyen pour que la fenetre se détruise apres avoir clické sur l'image, parce que placé la, ton code va la détruire des son ouverture :s
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=
    (\_/)
    (O.o)
    (> <)
    This is Bunny. Copy Bunny into your signature to help him on his way to world domination!!
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=

  4. #4
    Membre éclairé Avatar de slimjoe
    Homme Profil pro
    Inscrit en
    Juin 2005
    Messages
    647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Canada

    Informations forums :
    Inscription : Juin 2005
    Messages : 647
    Points : 789
    Points
    789
    Par défaut Re: fonction impossible sur form créée a la volée :s
    Citation Envoyé par avogadro
    Bonjour,
    En fait j'utilise ce code :

    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
    var
        my_picture : TImage; 
        photo : string; 
    begin 
         my_form := TForm.Create(self);
         my_picture := TImage.Create(my_form);
         with my_picture do 
              begin 
                   photo := Application.GetNamePath + 'vnp1.jpg'; 
              if FileExists(photo) then 
                begin
                   my_picture.Picture.LoadFromFile(photo);
                   Align := alclient;
                   my_form.height := my_picture.picture.height;
                   my_form.width := my_picture.picture.width;
                   parent := My_form;
                   Visible := true;
                   Onclick := close;
                end 
              else ShowMessage('La photo est introuvable'); 
              end;
         with my_form do
              begin
                   BorderStyle := bsNone;
                   Position := poScreenCenter;
                   Visible := true;
                   // ou ici : Onclick := close;               
              end;
    end;
    mais la ligne
    ne fonctionne pas, de meme si je souhaite avoir les paramètre du dragover de l'image1 sur cette my_picture, est ce que avec un code comme celui ci ça serait possible??
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    OnDragOver := Image1.OnDragOver;
    merci pour votre aide !
    Salut!

    Je ne suis pas certain de bien saisir le problème, mais je crois que la propriété OnClick de TImage attend une méthode de type TNotifyEvent. Est-ce que Close() est une méthode TNotifyEvent dans ton application ?

    Sinon, implémente une méthode dans ta classe de base (disons TForm1) et assigne la méthode à la propriété OnClick.

    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;
     
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
     
        procedure MyOnClick(Sender: TObject);
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.Button1Click(Sender: TObject);
    var
      my_picture: TImage;
      photo: string;
      my_form: TForm;
    begin
      my_form := TForm.Create(self);
      my_picture := TImage.Create(my_form);
      with my_picture do
      begin
        photo := 'c:\test.bmp';
        if FileExists(photo) then
        begin
          my_picture.Picture.LoadFromFile(photo);
          Align := alclient;
          my_form.height := my_picture.picture.height;
          my_form.width := my_picture.picture.width;
          parent := My_form;
          Visible := true;
          Onclick := MyOnClick;
        end
        else
          ShowMessage('La photo est introuvable');
      end;
      with my_form do
      begin
        BorderStyle := bsNone;
        Position := poScreenCenter;
        Show;
      end;
    end;
     
     
    procedure TForm1.MyOnClick(Sender: TObject);
    begin
      if Sender is TImage then
        with Sender as TImage do
          if Parent is TForm then
            with Parent as TForm do
              Release;
    end;
     
    end.
    En gros, ce qu'il faut retenir, c,est qu'un événement, ce n'est rien d'autre qu'une propriété dont le type n'est pas un integer ou un string mais une méthode d'objet. Lorsque l'on construit dynamiquement un composant, si on veut réagir aux événements, il faut leur assigner des méthodes.

    Bon dev!

    -Slimjoe
    -Slimjoe

  5. #5
    Membre habitué Avatar de avogadro
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    412
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 412
    Points : 188
    Points
    188
    Par défaut
    merci ça marche, jai compris le truc !!
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=
    (\_/)
    (O.o)
    (> <)
    This is Bunny. Copy Bunny into your signature to help him on his way to world domination!!
    =-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=

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

Discussions similaires

  1. [POO] Ecouteur onkeypress crée a la volé sur form
    Par boutmos dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 22/01/2009, 14h42
  2. [VB.NET] Exécuter une fonction VB sur un Datagrid
    Par MiJack dans le forum Windows Forms
    Réponses: 3
    Dernier message: 24/09/2004, 14h45
  3. Fonction LEFT sur champ de type "text" : méthodes
    Par MatthieuQ dans le forum Langage SQL
    Réponses: 4
    Dernier message: 08/06/2004, 11h15
  4. pb avec la fonction boolean sur eclipse
    Par mcay dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 31/05/2004, 09h37
  5. Ontop Sur form secondaire
    Par remixtech dans le forum Composants VCL
    Réponses: 2
    Dernier message: 17/03/2003, 22h08

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