Autor Beitrag
minipliman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Do 22.12.05 11:07 
also ich will n lottoprogramm programmieren
die eingabe soll mittels checkbox in eine listbox geschehen
habs schon soweit fertich, wenn man anhakt hängt er die zahl in die lisbox ein.
problem ist wenn man abhakt und wieder einhackt hängt er wieder ein, das soll er nicht wie mach ich das?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.CheckBox01Click(Sender: TObject);
 begin
  if CheckBox01.Checked = true
   then Listbox1.Items.Add('01');
 end;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Do 22.12.05 11:15 
versuchs mal so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.CheckBox01Click(Sender: TObject);
begin
if CheckBox01.Checked = true then
  Listbox1.Items.Add('01')
 else
  Listbox1.Items.Delete(Listbox1.Items.IndexOf('01'));
end;


so sollte das programm die zahl aus der Liste entfernen, wenn man sie abhakt.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Do 22.12.05 11:18 
Ich denke so !


Eine globale Variable nutzen !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 var FirstCheck : Boolean;

//im FormCreate
FirstCheck := False;

procedure TForm1.CheckBox01Click(Sender: TObject);  
 begin  
  if CheckBox01.Checked  and not FirstCheck then 
  begin
    Listbox1.Items.Add('01');  
    FirstCheck := True; 
  end;
 end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Do 22.12.05 11:20 
Deine Lösung ist nicht gut @chrisw, weil die Zahl wieder entfernt werden muss wenn die checkbox entchecked wird.
Seraph
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Do 22.12.05 11:45 
Ich bin zwar kein Lottospieler, jedoch bin ich mir ziemlich sicher,
dass es jede Zahl in einem Zahlenfeld nur einmal gibt?!?

Du musst jetzt also nurnoch überprüfen, ob die Liste bereits eine Zahl beinhaltet, welche die Checkbox anhängt! Wenn nein => häng an,
wenn ja => dann nicht!

Die Funktion dazu könnte bspw. so aussehen:
ausblenden volle Höhe Delphi-Quelltext
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:
var
 CurrentNumber: String;

procedure AddNumber();
var
 i: Integer;
 founded: Boolean;
begin
 founded := false;

 with Form1 do
  begin
   if(ListBox1.Items.Capacity > 0)
    then begin
     for i := 0 to ListBox1.Items.Capacity - 1 do
      begin
       if(ListBox1.Items.Strings[i] = CurrentNumber)
        then founded := true;
     end;
   end;

   if(founded = false)
    then ListBox1.Items.Add(CurrentNumber);

   founded := false;
 end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 CurrentNumber := CheckBox1.Caption;
 AddNumber();
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
 CurrentNumber := CheckBox2.Caption;
 AddNumber();
end;


Du könntest dir es natürlich noch einfacher machen und sagen,
wenn der user gehakt hat, ist die Checkbox einfach disabled!
Dann machst du halt noch nen Button dazu, wo drauf steht, "Neu" oder "Reset"!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 CheckBox1.Enabled := false;
end;


Das wird bei dir wie ich sehe aber sowieso ein wurschtelcode!
Du schreibst warscheinlich jetzt wirklich 48 mal oder was weiß ich wie viele
Felder das sind diese Prozedur[/delphi]?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.CheckBox01Click(Sender: TObject);  
 begin  
  if CheckBox01.Checked = true  
   then Listbox1.Items.Add('01');  
 end;


Schon mal was von einem ObjektArray gehört??????
Wenn es dich interressiert, wie das so viel einfacher geht,
dann schreib das hier rein!!!!!! Dann mach ich mir halt schnell die Arbeit!
Ansonsten nicht....

CU
Seraph

Moderiert von user profile iconChristian S.: Delphi-Tags repariert.

_________________
Wer früher stirbt ist länger tot!
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Do 22.12.05 11:50 
die zahl soll doch wieder raus beim entchecken der checkbox, oder hab ich da was falsch verstanden?
Seraph
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Do 22.12.05 11:54 
ich weiß au net!
Bin mir net so sicher, was er will!

Er sagt schließlich nicht, dass er will, dass die Zahl wieder gelöscht wird
beim abhaken!?! hmmm


Vielleicht sollte er auch mal wieder antworten oder so!!!!
Dem muss unbedingt das ObjektArray beigebracht werden, so programmiert kein
"Mensch" (sorry). Ist aber wirklich besser, wenn du das Array beherschen würdest, anstatt so statische Prozeduren hintereinander zu hängen! :D

_________________
Wer früher stirbt ist länger tot!
minipliman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Do 22.12.05 11:59 
noch ne frage:
wenn ich jetzt die zahlen sotieren will dann sotiert er ja nach ascii also meinetwegen 12 ist kleiner als 2 weil vorne ne 1 is, wie bekomm ich das hin das er die zahlen normal sotiert?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 22.12.05 12:04 
Das direkt in der Listbox zu machen ist afaik nicht möglich - da musst du dir ne eigene Sortierroutine schreiben. Fragen dazu aber bitte in einen neuen Thread!

_________________
We are, we were and will not be.
Seraph
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Do 22.12.05 13:14 
So!

Ich hab dir jetzt schnell mal den Teil deines Programms mit einem
ObjectArray (ArrayOf[0..48]) TCheckboxes geschrieben!

Schau's dir mal an!

Das einzige Objekt was von vorn herein existiert ist die ListBox1.
Da ich nicht genau weiß, wieviele Felder Lotto hat, bin ich einfach mal von
49 ausgegangen! Also 7 Spalten, 7 Zeilen:

ausblenden volle Höhe Delphi-Quelltext
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure CheckboxClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Checkbox: Array[0..48]of TCheckBox;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
 i, y, BoxIndex: Integer;
 CBleft, CBtop, Arrayleft, Arraytop: Integer;
 ListDistance: Integer;
begin
  //Checkboxen erstellen und Eigenschaften festlegen:
  for i := 0 to 48 do
   begin
    Checkbox[i] := TCheckBox.Create(Form1); //für Form1 Name der Form
    Checkbox[i].Parent := Form1;  //Parent: Wem gehört das Objekt an?
                                  //für Form1 Name der Form...
    Checkbox[i].Caption := IntToStr(i + 1); //+1 weil der Index bei 0 beginnt
    Checkbox[i].Height := 10;
    Checkbox[i].Width := 30;
    Checkbox[i].Tag := i; //mit diesem Tag kann die Checkbox identifiziert werden
    Checkbox[i].OnClick := CheckboxClick; //CheckboxClick = Name einer Procedure
                                          //der oben bei type Form class angegeben wird
  end;
  //--------------------------------------------------

  //positionen der Checkboxen festlegen:
  Arrayleft := 5//feld entfernt vom linken Rand der Form;
  Arraytop := 5;  //feld entfernt vom oberen Rand der Form;
  CBleft := Arrayleft;
  CBtop := Arraytop;
  BoxIndex := 0;

  for i := 0 to 6 do
   begin
    for y := 0 to 6 do
     begin
      Checkbox[BoxIndex].Left := CBleft;
      Checkbox[BoxIndex].Top := CBTop;
      CBleft := CBleft + Checkbox[0].Width + 15//Abstand zwischen den CB's
      BoxIndex := BoxIndex + 1;
    end;
    CBtop := CBtop + Checkbox[0].Height + 15//Abstand zwischen den CB's
    CBleft := Arrayleft; //CBleft wieder auf position 1 setzen
  end;
  //---------------------------------------------------

  //listbox positionieren:
  ListDistance := 20//Abstand zwischen Array und ListBox
  ListBox1.Left := (7 * Checkbox[0].Width) + Arrayleft + (6 * 15) + ListDistance;

end;

procedure TForm1.CheckboxClick(Sender: TObject);
var
 t: Integer;
begin
 t :=(Sender as TCheckBox).Tag;
 //t ist nun der vorhin festgelegte Tag, der geklickten Checkbox

 if Checkbox[t].Checked = true
  then ListBox1.Items.Add(IntToStr(t + 1))
 else
  ListBox1.Items.Delete(ListBox1.Items.IndexOf(IntToStr(t + 1)));  

end;

end.


Hinweiß:
Der Code kann so wie er ist eingefügt und compiliert werden.
Nur die "ListBox1" muss noch auf die Form gesetzt werden!

Grüsse
Seraph

_________________
Wer früher stirbt ist länger tot!
roemer
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 10.01.06 12:38 
wenn du nun aber die listbox auf die form bringst, hast ja nix gewonnenm, denn die checkboxen fehlen doch und wenn ich die bei mir ebenfalls einfüge klappt das nit oder hab ich was verpennt, wie du das meinst? gruß
Seraph
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 163

Windows.:siXPack:.
Delphi7 Professional
BeitragVerfasst: Di 10.01.06 14:03 
user profile iconroemer hat folgendes geschrieben:
...die checkboxen fehlen doch...


Das intelligente an einem ObjektArray ist ja gerade, das keines der Objekte
hier Checkboxen wirklich von vorn herein existiert!!!

Es wird doch hier erst noch 49 mal erstellt!
=> 49 Checkboxen!!! Das kann man dem Code aber auch entnehmen!

ist ja auch egal! Du musst den code komplett einfügen und dann natürlich noch eine Verbindung zwischen FormCreate und dem eingefügten Code herstellen!
Also Form->Ereignisse->onCreate Doppelklick!!!

Die Listbox nicht vergessen! Glaub mir, das läuft!

Gruß Seraph

_________________
Wer früher stirbt ist länger tot!