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 checklistbox de delphi


Sujet :

Delphi

  1. #1
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut fonction checklistbox de delphi
    Bonjour,

    Comment puis-je testé l'items d'une checklistbox ? à savoir si celle si est coché ou pas ?

    J'ai essayé ça

    if CheckListBox1.ClassNameIs('nom de l'Items')=true ou false then ...

    Mais ça ne fonctionne pas

    Merci

  2. #2
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    C'est Checked qui permet de savoir si l'item est sélectionné ou non

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    If   CheckListBox1.Checked[checkListBox1.IndexOf('Nom de l''item')] then

  3. #3
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 586
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 586
    Points : 25 262
    Points
    25 262
    Par défaut
    TCheckListBox est une classe et non une fonction
    Et je te l'avais déjà dit dans le sujet action dans listbox qu'il fallait utiliser Checked[]

    Citation Envoyé par ShaiLeTroll Voir le message
    Sinon, utilise une TCheckListBox, ou tu peux cocher et décocher des items
    Ton Bouton Auto lira les Checked[] pour savoir quel programme installé
    Tu n'as même cherché à lire l'aide alors que j'ai fourni les mots clés !

    D'où tu sors ClassNameIs ? As-tu au moins LU la documentation en ligne en cliquant sur ce lien ???
    Cela n'a aucun rapport !

    Arrête de bricoler n'importe quoi n'importe comment !
    Tu te lances dans la programmation, fait le sérieusement, lit l'aide !
    C'est ça être débutant, il faut être patient, et lire des pages de documentation, c'est ce comme ça que j'ai appris en tout cas !

  4. #4
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut
    ok merci Rayek, en fait je suis passer par un test :


    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
    procedure TForm1.Button1Click(Sender: TObject);
     
    var
    i:integer;
     
    begin
     
    for i:=0 to (nbr_app-1) do
         begin
              if checklistbox1.Checked[i] then
              begin
                    if  CheckListBox1.Items[i]='Install Dropbox' then
                    ShellExecute(Handle,'open',adr_Dropbox,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install Msql') then
                    ShellExecute(Handle,'open',adr_Msql,nil,Nil,SW_SHOWDEFAULT);
                    if ((CheckListBox1.Items[i]= 'Install ixxat')and sev) then
                    ShellExecute(Handle,'open',adr_ixxat_sev,nil,Nil,SW_SHOWDEFAULT);
                    if ((CheckListBox1.Items[i]= 'Install ixxat')and wxp) then
                    ShellExecute(Handle,'open',adr_ixxat_wxp,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install MPLAB') then
                    ShellExecute(Handle,'open',adr_MPLAB,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install FTDI') then
                    ShellExecute(Handle,'open',adr_FTDI,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install teamviewer') then
                    ShellExecute(Handle,'open',adr_teamviewer,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install IFM') then
                    ShellExecute(Handle,'open',adr_IFM,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install VALENCE') then
                    ShellExecute(Handle,'open',adr_VALENCE,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install VENSCO') then
                    ShellExecute(Handle,'open',adr_VENSCO,nil,Nil,SW_SHOWDEFAULT);
                    if (CheckListBox1.Items[i]= 'Install InitMysql') then
                                          begin
                                          DeleteFile(adr_InitMysql_pc);
                                          CopyFile(adr_InitMysql,adr_InitMysql_pc,true);
                                          ShellExecute(Handle,'open',adr_serMysql,nil,Nil,SW_SHOWDEFAULT);
                                          end;
                    if  CheckListBox1.Items[i]='Install Dropbox' then
                    ShortCutDesktop;
              end;
     
          end;
    end;
    certain penserai qu'il y a plus simple mais ça fonctionne !!

    ShaiLeTroll, tu me la certainement déjà dit et je te remerci de me le rappeler, seulement comme tu dis je suis débutant et je me renseigne pas mal, seulement en programmation il y a parfois plusieurs façons de faire un tache et dans les forum chacun résonne différemment quand on est plus aguerri en prog les mots clé utilisé en recherche sont plus optimisé et donc plus de chance de cibler l'info !!

    Je ne connais pas toutes les possibilités qu'offre delphi, je me renseigne dans les bouquins, forum,... mais si je passe tout mon temps dans les bouquins je n'avance pas dans mon programme, j'ai des délais à respecter.

    Les réflexes de programmation vient en pratiquant, c'est comme une langue, plus tu parle et plus tu est à l'aise.
    Maintenant on n'est pas tous égaux devant l'apprentissage.

  5. #5
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Ton code écrit d'une autre manière

    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
     
    uses StrUtils, .... ;
    // ...
     
    Var
      sProg : String;
    // begin
    for i:=0 to (nbr_app-1) do
    begin
      if checklistbox1.Checked[i] then
      begin
        Case AnsiIndexStr(CheckListBox1.Items[i],[ 'Install Dropbox','Install Msql', 'Install ixxat','Install MPLAB', 'Install FTDI', 'Install teamviewer', 'Install IFM',
    'Install VALENCE',  'Install VENSCO', 'Install InitMysql', 'Install Dropbox']) of
          0: sProg := adr_Dropbox; 
          1: sProg := adr_Msql;       
          2: sProg := adr_ixxat_sev;
          3: sProg := adr_MPLAB;
          4: sProg := adr_FTDI;
          5: sProg := adr_teamviewer;
          6: sProg := adr_IFM;
          7: sProg := adr_VALENCE;
          8: sProg := adr_VENSCO;
          9: begin
             sProg := adr_serMysql
             DeleteFile(adr_InitMysql_pc);
             CopyFile(adr_InitMysql,adr_InitMysql_pc,true);
          end;
          10: begin
            sProg := '';
            ShortCutDesktop;
          end;
          else
            sProg := '';
       end;
      If sProg <> '' then
      begin
        ShellExecute(Handle,'open',sProg,nil,Nil,SW_SHOWDEFAULT);
        if wxp and (sProg = adr_ixxat_sev) then
          ShellExecute(Handle,'open',adr_ixxat_wxp,nil,Nil,SW_SHOWDEFAULT);
      end;
    end;

  6. #6
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut
    Effectivement, un case serai plus judicieux dans ce cas là, je vais faire ça dès lundi au bureau.

    Merci Rayek

  7. #7
    Membre expert

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2007
    Messages
    3 487
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 487
    Points : 3 120
    Points
    3 120
    Par défaut Pour faire plaisir à ShaiLeTroll


    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, CheckLst;
     
    type
     
      TIntegerArray = array of Integer;
     
      TForm1 = class(TForm)
        chklst1: TCheckListBox;
        btn1: TButton;
        procedure btn1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
    type
      TExe = class
        nom: string;
        constructor create(_nom: string);
        class function NewExe(nom: string): TExe;
      end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      chklst1.Clear;
      chklst1.Items.AddObject('Install Dropbox', TExe.NewExe('install_dropbox'));
      chklst1.Items.AddObject('Install Msql',    TExe.NewExe('install_msql'));
      chklst1.Items.AddObject('Install ixxat',   TExe.NewExe('install_ixxat'));
    end;
     
    function getCheckedItems(chklst: TCheckListBox): TIntegerArray;
    var
      i, j: Integer;
    begin
      SetLength(Result, 0);
      j := 0;
      for i := 0 to Pred(chklst.Count) do
        if chklst.Checked[i] then
        begin
          Inc(j);
          SetLength(Result, j);
          Result[j - 1] := i;
        end;
    end;
     
    procedure TForm1.btn1Click(Sender: TObject);
    var
      i: Integer;
      exe: TExe;
      result: TIntegerArray;
    begin
      result := getCheckedItems(chklst1);
      for i := Low(result) to High(result) do
      begin
        exe := TExe(chklst1.Items.Objects[result[i]]);
        ShowMessage(exe.nom);
      end;
    end;
     
    { TExe }
     
    constructor TExe.create(_nom: string);
    begin
      inherited create;
      nom := _nom;
    end;
     
    class function TExe.NewExe(nom: string): TExe;
    begin
      Result := TExe.create(nom);
    end;
     
    end.

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

Discussions similaires

  1. Pb Fonction Power sous Delphi 7
    Par kimlee dans le forum Débuter
    Réponses: 2
    Dernier message: 25/05/2009, 14h57
  2. la fonction split en delphi
    Par toutou2000 dans le forum Débuter
    Réponses: 7
    Dernier message: 06/11/2008, 17h37
  3. Ancienne fonction TP7 en Delphi
    Par mpetri dans le forum Langage
    Réponses: 5
    Dernier message: 20/03/2008, 18h37
  4. Comment appeler une fonction JavaScript depuis Delphi ?
    Par Alfred12 dans le forum Web & réseau
    Réponses: 4
    Dernier message: 17/06/2005, 18h15
  5. Existe-t-il une fonction Eval() sous Delphi ?
    Par Hell dans le forum Langage
    Réponses: 5
    Dernier message: 20/12/2004, 17h45

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