Autor Beitrag
Terra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 307

Windows 7 Ultimate
Delphi® XE3
BeitragVerfasst: Mo 20.03.06 13:23 
Servuz,

Hab da ein kleines Problemchen...
Ich habe 3 Comboboxen, die alle mittels Array gefüttert werden.

Am Anfang klappt auch alles supertoll..
array1 : array[0..1] of string = ('a','b');
array2 : array[0..1] of string = ('x','y');
for i do array1...combobox1.items.add(i)...

naja, wie man so halt ne Combobox mittels Array aufruft... Alle Comboboxen sind miteinander Verschachtelt. Soll heißen, das wenn die erste Combobox ein bestimmten Inhalt angeklickt wird gleichzeitig in der 2. und evtl. auch in der 3. Combobox was aufgeführt wird was in den anderen Arrays steht.
Soweit geht auch alles, allerdings hab ich das Problem, das wenn ich beim Start ohne weiteren (zusätzlichen) Quellcode mein Programm aufrufe, steht wie oben gesagt alles schön sauber in den Boxen drinn. Veränder ich doch Was in der 1. Combobox, fügt der in der 2. Box den Inhalt des anderen Array hinzu anstatt den zu ersetzen!

sieht dann in etwa so aus:
normalerweise:

a
b

bei mir nach änderrung:

a
b
x
y

soll aber nach änderrung nur:

x
y

anzeigen.

Gibt es ein Befehl anstelle ".Add()" der mein Problem löst?

Ich habe es schon überall mit Combobox.Items.Clear; versucht. Dabei zeigt der dann aber immer nur den 1. Teil des Arrays in den Comboboxen. Zwar funktioniert das dann ungefähr so, wie ich es haben will aber aber er löscht immer wieder den Inhalt der 2. und 3. Combobox und springt auf den jeweils 1. Eintrag zurück.

Terra
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Mo 20.03.06 13:58 
ausblenden Delphi-Quelltext
1:
ComboBox.Items[0] := 'neu'					

sollte das sein, was Du sucht, allerdings Vorsicht, gibt es den Index nicht, kommt 'ne Exception
//EDIT
also so zBsp:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure AddItem (const C: TComboBox; const AItem: String; const AIndex: Integer);
begin
  if AIndex<C.Items.Count then C.Items[AIndex] := AItem
                          else C.Items.Add (AItem);
end;

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Terra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 307

Windows 7 Ultimate
Delphi® XE3
BeitragVerfasst: Mo 20.03.06 14:05 
Hmm .. sieht wieder nach viel Arbeit aus aber trotzdem danke. .. .werds mal ausprobieren.

Terra
Terra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 307

Windows 7 Ultimate
Delphi® XE3
BeitragVerfasst: Mi 29.03.06 11:38 
Wohl doch nicht... ok, nochmal zur erklärung...

Ich habe 3 Comboboxen ... alle auf einem Form.

In der 1. Combobox lade ich mit hilfe eines Arrays den Inhalt in die Combobox.
Je nach auswahl der 1. Combobox wird in der 2. Combobox wiederrum der Inhalt eines anderen Array eingefügt.

nehemn wir an, array1 ist in der ersten combo drinn:

ausblenden Delphi-Quelltext
1:
array1 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');					


jetzt erstell ich noch 3 weitere arrays um die 2. combobox zu füllen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
array2 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');
array3 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');
array4 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');

case combobox1.. do
0 : begin trage_array1_in_combobox2_ein; end;
1 : begin trage_array2_in_combobox2_ein; end;
2 : begin trage_array3_in_combobox2_ein; end;
end;

gehen wir ein schritt weiter ....

habe noch mehr arrays für die 3. Combobox.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
array5 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');
array6 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');
array7 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');
array8 : array[0..2] of string ('Nummer1','Nummer2','Nummer3');


nehmen wir die erste case anweisung und fügen nun noch die 3. zur auswahl hinzu:

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:
procedure combobox_anweisung(sender: TObject);
case combobox1.. do
0 : begin 
    trage_array1_in_combobox2_ein; 
      case combobox2.. do
      0 : begin 
          trage_array5_in_combobox3_ein;
             case .... end;
          end;
      1 : begin
          trage_array6_in_combobox3_ein;
             case .... end;
        end;
      end;
    end;
1 : begin 
    trage_array2_in_combobox2_ein;
    case combobox2.. do
      0 : begin 
          trage_array5_in_combobox3_ein;
            case .... end;
          end;
      1 : begin
          trage_array8_in_combobox3_ein;
            case .... end;
        end;
      end; 
    end;
2 : begin 
    trage_array3_in_combobox2_ein; 
      case combobox2.. do
      0 : begin 
          trage_array5_in_combobox3_ein;
             case .... end;
          end;
      1 : begin
          trage_array7_in_combobox3_ein;
              case .... end;
          end;
      end;
    end;
end;
end;


stelle ich jetzt vor der case anweisung ein combo2.clear; rein löscht er zwar den alten inhalt aber das macht er ständig. (im grunde genommen habe ich 3 comboboxen, wo wenn ich im 3. was ändere er auch den 2. löscht was er aber nicht machen soll)

Ich komm einfach nicht weiter ... hat jemand ne andere lösung ?
Sehr möglich, das die Quelltexte nicht 100% stimmen. Es ging mir eigentlich nur um den Aufbau.

Terra


Zuletzt bearbeitet von Terra am Mi 29.03.06 12:36, insgesamt 2-mal bearbeitet
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mi 29.03.06 12:29 
Zeig mal den ganzen Code, der mit den Comboboxen zu tu hat. Das versteht doch kein Mensch was du hier willst. :shock:


MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Terra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 307

Windows 7 Ultimate
Delphi® XE3
BeitragVerfasst: Mi 29.03.06 12:34 
Hab den Quelltext selber nicht hier auf Arbeit ... hab das aber mal in etwa so aufgeschlüsselt wie ich es in erinnerung habe.

Terra
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mi 29.03.06 15:32 
Ich hab mal ein wenig rum gespielt... :lol:

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:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    Button1: TButton;
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure FillMyArray;
    procedure Button1Click(Sender: TObject);
  private
    Array1: array[0..2] of string;
    Array2: array[0..2, 0..2] of string;
    MyArray: array[0..2, 0..2, 0..2] of string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  i: Integer;
begin
  if ComboBox1.ItemIndex > -1 then
    begin
      ComboBox2.Clear;
      ComboBox3.Clear;
      for i := 0 to 2 do
        ComboBox2.Items.Add(Array2[ComboBox1.ItemIndex, i]);
    end;
end;

procedure TForm1.ComboBox2Change(Sender: TObject);
var
  i: Integer;
begin
  if (ComboBox1.ItemIndex > -1) and (ComboBox2.ItemIndex > -1)then
    begin
      ComboBox3.Clear;
        for i := 0 to 2 do
          ComboBox3.Items.Add(MyArray[ComboBox1.ItemIndex, ComboBox2.ItemIndex, i]);
    end;
end;

procedure TForm1.FillMyArray;
//var
//  i, j, k: Integer;
//  lCounter: Integer;
begin
//  lCounter := 1;
//  for i := 0 to 2 do
//    for j := 0 to 2 do
//      for k := 0 to 2 do
//        begin
//          MyArray[i, j, k] := Format('Nummer%d', [lCounter]);
//          Inc(lCounter);
//        end;

  Array1[0] := 'Pflanzen';
  Array1[1] := 'Menschen';
  Array1[2] := 'Tiere';

  Array2[0, 0]  := 'Sträucher';
  Array2[0, 1]  := 'Bäume';
  Array2[0, 2]  := 'Blumen';

  Array2[1, 0]  := 'Mann';
  Array2[1, 1]  := 'Frau';
  Array2[1, 2]  := 'Kind';

  Array2[2, 0]  := 'Flugtiere';
  Array2[2, 1]  := 'Wassertiere';
  Array2[2, 2]  := 'Landtiere';

  MyArray[0, 0, 0]  := 'Brombeere';
  MyArray[0, 0, 1]  := 'Heidelbeere';
  MyArray[0, 0, 2]  := 'Stachelbeere';

  MyArray[0, 1, 0]  := 'Eiche';
  MyArray[0, 1, 1]  := 'Buche';
  MyArray[0, 1, 2]  := 'Linde';

  MyArray[0, 2, 0]  := 'Rose';
  MyArray[0, 2, 1]  := 'Tulpe';
  MyArray[0, 2, 2]  := 'Lilie';

  MyArray[1, 0, 0]  := 'Bernd';
  MyArray[1, 0, 1]  := 'Uwe';
  MyArray[1, 0, 2]  := 'Kai';

  MyArray[1, 1, 0]  := 'Angela';
  MyArray[1, 1, 1]  := 'Michaela';
  MyArray[1, 1, 2]  := 'Susanne';

  MyArray[1, 2, 0]  := 'Kind1';
  MyArray[1, 2, 1]  := 'Kind2';
  MyArray[1, 2, 2]  := 'Kind3';

  MyArray[2, 0, 0]  := 'Taube';
  MyArray[2, 0, 1]  := 'Spatz';
  MyArray[2, 0, 2]  := 'Geier';

  MyArray[2, 1, 0]  := 'Rochen';
  MyArray[2, 1, 1]  := 'Forelle';
  MyArray[2, 1, 2]  := 'Hecht';

  MyArray[2, 2, 0]  := 'Hund';
  MyArray[2, 2, 1]  := 'Katze';
  MyArray[2, 2, 2]  := 'Maus';

//  for i := 0 to 2 do
//    for j := 0 to 2 do
//      for k := 0 to 2 do
//        ListBox1.Items.Add(MyArray[i, j, k]);

end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  FillMyArray;
  ComboBox1.Clear;
  for i := 0 to 2 do
    ComboBox1.Items.Add(Array1[i]);
end;

end.


Wenn einer einen Weg zur Vereinfachung sieht, bitte posten! ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mi 29.03.06 16:02 
Moin :-)
Auch ich hab ein bischen experimentiert ;-)
Entscheidend ist ja, dass das Befüllen der 'abhängigen' ComboBoxen im jeweiligen OnChange bzw OnClick der auslösenden ComboBox erfolgen muss!
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:
procedure ComboBox1Change(Sender: TObject);
begin
  case ComboBox1.ItemIndex of
    0:  begin
          p_ComboBoxFuellen(array1, ComboBox2);
        end;
    1:  begin
          p_ComboBoxFuellen(array2, ComboBox2);
        end;
    2:  begin
          p_ComboBoxFuellen(array3, ComboBox2);
        end;
  end;
  //--expliziet aufrufen, damit ComboBox3 neu eingestellt werden kann
  ComboBox2Change(Self);
end;

procedure ComboBox2Change(Sender: TObject);
var  Auswahl: Integer;
begin
  Auswahl := (ComboBox1.ItemIndex +1)*10 + ComboBox2.ItemIndex;
  
  case Auswahl of
    10:  p_ComboBoxFuellen(array4, ComboBox3);
    11:  p_ComboBoxFuellen(array5, ComboBox3);
    12:  p_ComboBoxFuellen(array6, ComboBox3);
    20:  p_ComboBoxFuellen(array5, ComboBox3);
    21:  p_ComboBoxFuellen(array8, ComboBox3);
    22:  p_ComboBoxFuellen(array6, ComboBox3);
    30:  p_ComboBoxFuellen(array7, ComboBox3);
    31:  p_ComboBoxFuellen(array5, ComboBox3);
    32:  p_ComboBoxFuellen(array6, ComboBox3);
  end;
end;

procedure p_ComboBoxFuellen(pQuelle: Array of String; pZiel: TComboBox);
var   I: Integer;
begin
  pZiel.Items.Clear;
  for I := 0 to Length(pQuelle)-1 do
    pZiel.Items.Add( pQuelle[i]);
  //-- auf ersten Eintrag stellen  
  pZiel.ItemIndex := 0;
end;


Ich hab mich bei diesem Beispiel mal an den 'Vorgaben' von Terra orientiert...
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mi 29.03.06 16:22 
Ich würde dann gern mal des Ergebnis sehen, egal ob als *.exe oder mit SourceCode. ;)

@raiguen: Deine Lösung schau ich mir dann auch mal an, sieht nach dem ersten Durchsehen ganz gut aus :D

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mi 29.03.06 21:59 
Moin :-)
@freak4fun: nun ja, es gibt ja viele Wege, ein 'Problem' oder Aufgabe zu lösen ;-) Deine Variante ist auch nicht so übel...
Woher die Daten für die einzelnen Comboboxen kommen ist ja zweitrangig, gell? Interessant wird eigentlich das 'Auswerte-Ergbnis' nach der dritten ComboBox, wenn alle Stati der Comboboxen berücksichtigt werden müssen... :roll: :mrgreen:
Terra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 307

Windows 7 Ultimate
Delphi® XE3
BeitragVerfasst: Do 30.03.06 09:13 
Das sieht alles vielversprechend aus ... ich werde alles mal ausprobieren.

Danke für eure Hilfe.

Terra

PS: Tazächlich müssen bei der Auswertung alle Comboboxen berücksichtigt werden. Da kann ich (denk ich mal) ne procedure dafür missbrauchen. Doof ist halt nur, das ich ein Ergebniss mal nach 2 Comboboxen brauche oder mal nach 3. Sollte aber auch kein Problem sein, da ja die 3. Combobox bei 2 Abfragen ignoriert werden kann.