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

Composants VCL Delphi Discussion :

"Problème" avec TSpeedButton.Glyph


Sujet :

Composants VCL Delphi

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut "Problème" avec TSpeedButton.Glyph
    Bonjour messieurs,

    J'ai un petit soucis, si vous pouviez m'aider ce serait sympa, je vais essayer d'être claire:

    Sur ma classe (A) TForm principale, j'ai un TSpeedButton et un TImageList.

    J'ai créé une classe (B) héritée de TObject créée à partir de ma TForm principale, cette classe contient également un TSpeedButton et un TImageList qui est en fait le TSpeedButton et le TImageList de ma TForm principale.

    En résumé:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    B.Create;
    B.SpeedButton := A.SpeedButton;
    B.ImageList := A.ImageList;

    Dans B je cherche à modifier le Glyph du SpeedButton (dynamiquement donc).

    Dans ma classe B je fais (ma ImageList contient deux images différentes):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ImageList.GetBitmap(0,SpeedButton.Glyph);
    SpeedButton.Repaint;
    ou

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ImageList.GetBitmap(1,SpeedButton.Glyph);
    SpeedButton.Repaint;
    suivant une condition.

    Hors, au final, l'image ne change malheureusement pas..

    Merci d'avance pour votre aide..

    @+

  2. #2
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Salut
    Citation Envoyé par inox77 Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    B.Create;
    B.SpeedButton := A.SpeedButton;
    B.ImageList := A.ImageList;
    Ces 3 lignes me chagrine, ce n'est pas ainsi que créé une instante de la classe B ? Si ?

    @+ Claudius

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Cl@udius Voir le message
    Salut

    Ces 3 lignes me chagrine, ce n'est pas ainsi que créé une instante de la classe B ? Si ?

    @+ Claudius
    Si en effet, la classe B est construite de cette manière.
    Enfin j'ai résumé.. en réalité je fais directement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    B.create(SpeedButton,ImageList);
    et dans le constructeur j'attribue SpeedButton et ImageList à des variable privée de B

    A vrai dire je n'ai même pas fais le test de ce code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    ImageList.GetImage(0,SpeedButton.Glyph);
    SpeedButton.Repaint;
    directement et classiquement dans la classe principale pour voir si le problème vient de la classe B ou pas..

  4. #4
    Membre chevronné

    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    1 519
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 1 519
    Points : 2 153
    Points
    2 153
    Billets dans le blog
    1
    Par défaut
    Oui mais si B est le nom de la variable alors on doit écrire l'instanciation comme ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    var
      B: TMaClasse;
    begin
      B := TMaClasse.Create( SpeedButton,ImageList );
    end;
    La FAQ - les Tutoriels - Le guide du développeur Delphi devant un problème

    Pas de sollicitations techniques par MP -

  5. #5
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Re,

    Ben ce n'est pas ainsi que l'on créé une instance de classe sous Delphi.

    J'ai fais cette exemple rapidement, qui s'approche de ta situation:
    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
     
    type
      TClassB = class(TObject)
      private
        ImageList: TImageList;
        SpeedButton: TSpeedButton;
      public
        constructor Create(Btn: TSpeedButton; ImgList: TImageList); 
        procedure ChangeGlyph(const Index: Integer);
      end;
     
      TForm1 = class(TForm)
        SpeedButton1: TSpeedButton;
        ImageList1: TImageList;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
        FClassB: TClassB;
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    { TForm1 }
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FClassB := TClassB.Create(SpeedButton1, ImageList1);
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FClassB.Free;
    end;
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      FClassB.ChangeGlyph(1);
    end;
     
    { TClassB }
     
    procedure TClassB.ChangeGlyph(const Index: Integer);
    begin
      ImageList.GetBitmap(Index, SpeedButton.Glyph);
      SpeedButton.Repaint;
    end;
     
    constructor TClassB.Create(Btn: TSpeedButton; ImgList: TImageList);
    begin
      inherited Create;
      SpeedButton := Btn;
      ImageList := ImgList;
    end;
     
    end.
    La ligne importante est celle-ci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      FClassB := TClassB.Create(SpeedButton1, ImageList1);
    @+ Claudius

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Cl@udius Voir le message
    Re,

    Ben ce n'est pas ainsi que l'on créé une instance de classe sous Delphi.

    J'ai fais cette exemple rapidement, qui s'approche de ta situation:
    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
     
    type
      TClassB = class(TObject)
      private
        ImageList: TImageList;
        SpeedButton: TSpeedButton;
      public
        constructor Create(Btn: TSpeedButton; ImgList: TImageList); 
        procedure ChangeGlyph(const Index: Integer);
      end;
     
      TForm1 = class(TForm)
        SpeedButton1: TSpeedButton;
        ImageList1: TImageList;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
        FClassB: TClassB;
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    { TForm1 }
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      FClassB := TClassB.Create(SpeedButton1, ImageList1);
    end;
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      FClassB.Free;
    end;
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      FClassB.ChangeGlyph(1);
    end;
     
    { TClassB }
     
    procedure TClassB.ChangeGlyph(const Index: Integer);
    begin
      ImageList.GetBitmap(Index, SpeedButton.Glyph);
      SpeedButton.Repaint;
    end;
     
    constructor TClassB.Create(Btn: TSpeedButton; ImgList: TImageList);
    begin
      inherited Create;
      SpeedButton := Btn;
      ImageList := ImgList;
    end;
     
    end.
    La ligne importante est celle-ci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      FClassB := TClassB.Create(SpeedButton1, ImageList1);
    @+ Claudius
    Tout a fait..

    Je suis resté très symbolique dans le code posté.

  7. #7
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Citation Envoyé par inox77 Voir le message
    Je suis resté très symbolique dans le code posté.
    Ah, peut-être un peu trop alors...

    Montre-nous le code de ta classe B (ou les extraits qui posent problème).

  8. #8
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Cl@udius Voir le message
    Ah, peut-être un peu trop alors...

    Montre-nous le code de ta classe B (ou les extraits qui posent problème).
    ok

    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
    constructor TSession.Create(identity:string;button:TSpeedButton;imagelist:TImagelist);
    begin
      inherited create;
     
      FButton := button;
      FImageList := imagelist;
      FIdentity := identity;
      FConnected := false;
     
      FSocket := TWSocket.Create(nil);
      FSocket.OnDataAvailable := OnDataAvailable;
      FSocket.OnSessionClosed := OnSessionClosed;
      FSocket.OnSessionConnected := onsessionconnected;
     
      FTimerTelnet := TTimer.Create(nil);
      FTimerTelnet.OnTimer := OnTimerSession;
      FTimerTelnet.Enabled := false;
    end;
     
    procedure TSession.OnDataAvailable(sender : TObject;ErrCode:Word);
    var ch : string;
    begin
      If ErrCode = 0 then
      begin
        ch := FSocket.ReceiveStr;
     
        if pos('220',ch) <> 0 then
        begin
          FImageList.GetBitmap(0,FButton.Glyph);
          FButton.Repaint;
          FConnected := true;
        end
        else
        begin
          FImageList.GetBitmap(1,FButton.Glyph);
          FButton.Repaint;
          FConnected := false;
        end;
      end;
     
      FSocket.Close;
    end;
    voila c'est une routine pour vérifier qu'un serveur FTP est bien actif. Un peu bourrin je trouve mais j'ai pas trouvé mieux. Au début j'utilisais un TImage à la place du TSpeedButton.

    et le code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
          FImageList.GetIcon(1,FImage.Icon);
          FImage.Repaint;
          FConnected := false;
    fonctionnait très bien.

    Merci de ton attention.

  9. #9
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    je viens de faire un test tout simple sur une forme quelquonque et le problème est toujours la, rien a voir avec la classe en fait.

    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
    type
      TForm23 = class(TForm)
        SpeedButton1: TSpeedButton;
        ImageList1: TImageList;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      Form23: TForm23;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm23.Button1Click(Sender: TObject);
    begin
            imagelist1.GetBitmap(0,speedbutton1.Glyph);
            speedbutton1.Repaint;
    end;
     
    procedure TForm23.Button2Click(Sender: TObject);
    begin
            imagelist1.GetBitmap(1,speedbutton1.Glyph);
            speedbutton1.Repaint;
    end;
     
    end.
    quand on clique une première fois ca fonctionne. mais par la suite rien a faire, il garde la première image chargée.

  10. #10
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Citation Envoyé par inox77 Voir le message
    quand on clique une première fois ca fonctionne. mais par la suite rien a faire, il garde la première image chargée.
    Ah oui exact !

  11. #11
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Essaye comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    procedure TClassB.ChangeGlyph(const Index: Integer);
    var
      Bmp: TBitmap;
    begin
      Bmp := TBitmap.Create;
      try
        FImageList.GetBitmap(Index, Bmp);
        FSpeedButton.Glyph.Assign(Bmp);
        FSpeedButton.Repaint;
      finally
        Bmp.Free;
      end;
    end;

  12. #12
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Cl@udius Voir le message
    Essaye comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    procedure TClassB.ChangeGlyph(const Index: Integer);
    var
      Bmp: TBitmap;
    begin
      Bmp := TBitmap.Create;
      try
        FImageList.GetBitmap(Index, Bmp);
        FSpeedButton.Glyph.Assign(Bmp);
        FSpeedButton.Repaint;
      finally
        Bmp.Free;
      end;
    end;
    Parfait ca fonctionne.. Je perd les propriétés de transparence mais je vais tricher un peu

    Merci beaucoup

  13. #13
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Ouais ben c'était tout bête !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    procedure TClassB.ChangeGlyph(const Index: Integer);
    begin
      with FButton do
      begin
        Glyph := nil;
        FImageList.GetBitmap(Index, Glyph);
        Repaint;
      end;
    end;
    [edit]
    Ah au fait, bienvenue sur les forums de DVP.

  14. #14
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 8
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Cl@udius Voir le message
    Ouais ben c'était tout bête !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    procedure TClassB.ChangeGlyph(const Index: Integer);
    begin
      with FButton do
      begin
        Glyph := nil;
        FImageList.GetBitmap(Index, Glyph);
        Repaint;
      end;
    end;
    [edit]
    Ah au fait, bienvenue sur les forums de DVP.
    Merci bien. C'est la première fois que je demande de l'aide sur un forum et c'est bien plus sympa que de perdre son temps sur des bétises qui nous échappent.. J'aiderai à mon tour volontier.

    @+

  15. #15
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Citation Envoyé par inox77 Voir le message
    Merci bien.
    Avec plaisir.

    Un p'tit tag (juste en dessous), et ce sera nickel.

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

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