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
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
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
Modérateur Delphi
Le guide du bon forumeur :
- Les règles du forum tu liras
- La FAQ et les tutoriels tu consulteras
- La fonction Recherche tu utiliseras
- Google tu vénèreras
__________
Rayek World : Youtube Facebook
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[]
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 !
Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !![]()
Attention Troll Méchant !
"Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
L'ignorance n'excuse pas la médiocrité !
L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
Il faut avoir le courage de se tromper et d'apprendre de ses erreurs
ok merci Rayek, en fait je suis passer par un test :
certain penserai qu'il y a plus simple mais ça fonctionne !!
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;
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.
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;
Modérateur Delphi
Le guide du bon forumeur :
- Les règles du forum tu liras
- La FAQ et les tutoriels tu consulteras
- La fonction Recherche tu utiliseras
- Google tu vénèreras
__________
Rayek World : Youtube Facebook
Effectivement, un case serai plus judicieux dans ce cas là, je vais faire ça dès lundi au bureau.
Merci Rayek
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.
Partager