umständlicher C++ quelltext --> pls help!
Hey Leute!!
Ich muss ein Programm schreiben in C++ hab ein bisschen Grundwissen und so ein einfaches Programm, wie es von mir verlangt wird, hab ich schnell geschrieben.
Der Quelltext ist jedoch etwas umständlich und sicher seeehr verkürzbar. Ich weiß leider aber nicht, wie das in C++ möglich ist!
Vielleicht kann jemand von euch helfen, ich poste ihn mal:
Ich mein, da hats viele wiederholungen drin, die man vllt mit schleifen erledigen könnte. weiß nur nicht wie!
ich häng mal noch die fotographierte gui an:
Ich muss ein Programm schreiben in C++ hab ein bisschen Grundwissen und so ein einfaches Programm, wie es von mir verlangt wird, hab ich schnell geschrieben.
Der Quelltext ist jedoch etwas umständlich und sicher seeehr verkürzbar. Ich weiß leider aber nicht, wie das in C++ möglich ist!
Vielleicht kann jemand von euch helfen, ich poste ihn mal:
Ich mein, da hats viele wiederholungen drin, die man vllt mit schleifen erledigen könnte. weiß nur nicht wie!
|
|
Quellcode |
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
TForm1 *Form1;
bool simulate = 0;
int status = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnSimulateClick(TObject *Sender)
{
simulate = !simulate;
if(simulate == 1)btnSimulate->Caption = "anhalten";
if(simulate == 0)btnSimulate->Caption = "simulieren";
Timer1->Interval = StrToInt(edtSimSpeed->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(simulate)
{
stat0->Brush->Color = clWhite;
stat1->Brush->Color = clWhite;
stat2->Brush->Color = clWhite;
stat3->Brush->Color = clWhite;
Panel0->Color = clWhite;
Panel1->Color = clWhite;
Panel2->Color = clWhite;
Panel3->Color = clWhite;
Panel4->Color = clWhite;
Panel5->Color = clWhite;
Panel6->Color = clWhite;
Panel7->Color = clWhite;
Panel8->Color = clWhite;
Panel9->Color = clWhite;
PanelA->Color = clWhite;
PanelB->Color = clWhite;
PanelC->Color = clWhite;
PanelD->Color = clWhite;
PanelE->Color = clWhite;
PanelF->Color = clWhite;
bool A0 = 0,A1 = 0,A2 = 0,A3 = 0;
switch(status)
{
case 0: Panel0->Color = clRed;
A0 = bit00->Checked;
A1 = bit01->Checked;
A2 = bit02->Checked;
A3 = bit03->Checked;
break;
case 1: Panel1->Color = clRed;
A0 = bit10->Checked;
A1 = bit11->Checked;
A2 = bit12->Checked;
A3 = bit13->Checked;
break;
case 2: Panel2->Color = clRed;
A0 = bit20->Checked;
A1 = bit21->Checked;
A2 = bit22->Checked;
A3 = bit23->Checked;
break;
case 3: Panel3->Color = clRed;
A0 = bit30->Checked;
A1 = bit31->Checked;
A2 = bit32->Checked;
A3 = bit33->Checked;
break;
case 4: Panel4->Color = clRed;
A0 = bit40->Checked;
A1 = bit41->Checked;
A2 = bit42->Checked;
A3 = bit43->Checked;
break;
case 5: Panel5->Color = clRed;
A0 = bit50->Checked;
A1 = bit51->Checked;
A2 = bit52->Checked;
A3 = bit53->Checked;
break;
case 6: Panel6->Color = clRed;
A0 = bit60->Checked;
A1 = bit61->Checked;
A2 = bit62->Checked;
A3 = bit63->Checked;
break;
case 7: Panel7->Color = clRed;
A0 = bit70->Checked;
A1 = bit71->Checked;
A2 = bit72->Checked;
A3 = bit73->Checked;
break;
case 8: Panel8->Color = clRed;
A0 = bit80->Checked;
A1 = bit81->Checked;
A2 = bit82->Checked;
A3 = bit83->Checked;
break;
case 9: Panel9->Color = clRed;
A0 = bit90->Checked;
A1 = bit91->Checked;
A2 = bit92->Checked;
A3 = bit93->Checked;
break;
case 10:PanelA->Color = clRed;
A0 = bitA0->Checked;
A1 = bitA1->Checked;
A2 = bitA2->Checked;
A3 = bitA3->Checked;
break;
case 11:PanelB->Color = clRed;
A0 = bitB0->Checked;
A1 = bitB1->Checked;
A2 = bitB2->Checked;
A3 = bitB3->Checked;
break;
case 12:PanelC->Color = clRed;
A0 = bitC0->Checked;
A1 = bitC1->Checked;
A2 = bitC2->Checked;
A3 = bitC3->Checked;
break;
case 13:PanelD->Color = clRed;
A0 = bitD0->Checked;
A1 = bitD1->Checked;
A2 = bitD2->Checked;
A3 = bitD3->Checked;
break;
case 14:PanelE->Color = clRed;
A0 = bitE0->Checked;
A1 = bitE1->Checked;
A2 = bitE2->Checked;
A3 = bitE3->Checked;
break;
case 15:PanelF->Color = clRed;
A0 = bitF0->Checked;
A1 = bitF1->Checked;
A2 = bitF2->Checked;
A3 = bitF3->Checked;
break;
};
if(A0)stat0->Brush->Color = clRed;
if(A1)stat1->Brush->Color = clRed;
if(A2)stat2->Brush->Color = clRed;
if(A3)stat3->Brush->Color = clRed;
status++;
if(status > 15)status = 0;
};
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bit13Click(TObject *Sender)
{
int bit[16][4];
bit[0][0] = bit00->Checked;
bit[0][1] = bit01->Checked;
bit[0][2] = bit02->Checked;
bit[0][3] = bit03->Checked;
bit[1][0] = bit10->Checked;
bit[1][1] = bit11->Checked;
bit[1][2] = bit12->Checked;
bit[1][3] = bit13->Checked;
bit[2][0] = bit20->Checked;
bit[2][1] = bit21->Checked;
bit[2][2] = bit22->Checked;
bit[2][3] = bit23->Checked;
bit[3][0] = bit30->Checked;
bit[3][1] = bit31->Checked;
bit[3][2] = bit32->Checked;
bit[3][3] = bit33->Checked;
bit[4][0] = bit40->Checked;
bit[4][1] = bit41->Checked;
bit[4][2] = bit42->Checked;
bit[4][3] = bit43->Checked;
bit[5][0] = bit50->Checked;
bit[5][1] = bit51->Checked;
bit[5][2] = bit52->Checked;
bit[5][3] = bit53->Checked;
bit[6][0] = bit60->Checked;
bit[6][1] = bit61->Checked;
bit[6][2] = bit62->Checked;
bit[6][3] = bit63->Checked;
bit[7][0] = bit70->Checked;
bit[7][1] = bit71->Checked;
bit[7][2] = bit72->Checked;
bit[7][3] = bit73->Checked;
bit[8][0] = bit80->Checked;
bit[8][1] = bit81->Checked;
bit[8][2] = bit82->Checked;
bit[8][3] = bit83->Checked;
bit[9][0] = bit90->Checked;
bit[9][1] = bit91->Checked;
bit[9][2] = bit92->Checked;
bit[9][3] = bit93->Checked;
bit[10][0] = bitA0->Checked;
bit[10][1] = bitA1->Checked;
bit[10][2] = bitA2->Checked;
bit[10][3] = bitA3->Checked;
bit[11][0] = bitB0->Checked;
bit[11][1] = bitB1->Checked;
bit[11][2] = bitB2->Checked;
bit[11][3] = bitB3->Checked;
bit[12][0] = bitC0->Checked;
bit[12][1] = bitC1->Checked;
bit[12][2] = bitC2->Checked;
bit[12][3] = bitC3->Checked;
bit[13][0] = bitD0->Checked;
bit[13][1] = bitD1->Checked;
bit[13][2] = bitD2->Checked;
bit[13][3] = bitD3->Checked;
bit[14][0] = bitE0->Checked;
bit[14][1] = bitE1->Checked;
bit[14][2] = bitE2->Checked;
bit[14][3] = bitE3->Checked;
bit[15][0] = bitF0->Checked;
bit[15][1] = bitF1->Checked;
bit[15][2] = bitF2->Checked;
bit[15][3] = bitF3->Checked;
A0->Caption = " "+IntToStr(bit[0][3])+" "+IntToStr(bit[0][2])+" "+IntToStr(bit[0][1])+" "+IntToStr(bit[0][0])+" ";
A1->Caption = " "+IntToStr(bit[1][3])+" "+IntToStr(bit[1][2])+" "+IntToStr(bit[1][1])+" "+IntToStr(bit[1][0])+" ";
A2->Caption = " "+IntToStr(bit[2][3])+" "+IntToStr(bit[2][2])+" "+IntToStr(bit[2][1])+" "+IntToStr(bit[2][0])+" ";
A3->Caption = " "+IntToStr(bit[3][3])+" "+IntToStr(bit[3][2])+" "+IntToStr(bit[3][1])+" "+IntToStr(bit[3][0])+" ";
A4->Caption = " "+IntToStr(bit[4][3])+" "+IntToStr(bit[4][2])+" "+IntToStr(bit[4][1])+" "+IntToStr(bit[4][0])+" ";
A5->Caption = " "+IntToStr(bit[5][3])+" "+IntToStr(bit[5][2])+" "+IntToStr(bit[5][1])+" "+IntToStr(bit[5][0])+" ";
A6->Caption = " "+IntToStr(bit[6][3])+" "+IntToStr(bit[6][2])+" "+IntToStr(bit[6][1])+" "+IntToStr(bit[6][0])+" ";
A7->Caption = " "+IntToStr(bit[7][3])+" "+IntToStr(bit[7][2])+" "+IntToStr(bit[7][1])+" "+IntToStr(bit[7][0])+" ";
A8->Caption = " "+IntToStr(bit[8][3])+" "+IntToStr(bit[8][2])+" "+IntToStr(bit[8][1])+" "+IntToStr(bit[8][0])+" ";
A9->Caption = " "+IntToStr(bit[9][3])+" "+IntToStr(bit[9][2])+" "+IntToStr(bit[9][1])+" "+IntToStr(bit[9][0])+" ";
AA->Caption = " "+IntToStr(bit[10][3])+" "+IntToStr(bit[10][2])+" "+IntToStr(bit[10][1])+" "+IntToStr(bit[10][0])+" ";
AB->Caption = " "+IntToStr(bit[11][3])+" "+IntToStr(bit[11][2])+" "+IntToStr(bit[11][1])+" "+IntToStr(bit[11][0])+" ";
AC->Caption = " "+IntToStr(bit[12][3])+" "+IntToStr(bit[12][2])+" "+IntToStr(bit[12][1])+" "+IntToStr(bit[12][0])+" ";
AD->Caption = " "+IntToStr(bit[13][3])+" "+IntToStr(bit[13][2])+" "+IntToStr(bit[13][1])+" "+IntToStr(bit[13][0])+" ";
AE->Caption = " "+IntToStr(bit[14][3])+" "+IntToStr(bit[14][2])+" "+IntToStr(bit[14][1])+" "+IntToStr(bit[14][0])+" ";
AF->Caption = " "+IntToStr(bit[15][3])+" "+IntToStr(bit[15][2])+" "+IntToStr(bit[15][1])+" "+IntToStr(bit[15][0])+" ";
}
//---------------------------------------------------------------------------
|
ich häng mal noch die fotographierte gui an:
gReEtZ bY traZor
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »invisible« (29. Dezember 2004, 01:47)
es soll als "schöner" "übersichtlicher" quelltext abgeliefert werden... klar, ich weiß, dass ichs lassen soll, wenn's funzt...
Aber kann man solche Bereiche nicht durch ne schleife verkürzen?
oder das:
oder das auf jeden fall
Aber kann man solche Bereiche nicht durch ne schleife verkürzen?
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Panel0->Color = clWhite; Panel1->Color = clWhite; Panel2->Color = clWhite; Panel3->Color = clWhite; Panel4->Color = clWhite; Panel5->Color = clWhite; Panel6->Color = clWhite; Panel7->Color = clWhite; Panel8->Color = clWhite; Panel9->Color = clWhite; PanelA->Color = clWhite; PanelB->Color = clWhite; PanelC->Color = clWhite; PanelD->Color = clWhite; PanelE->Color = clWhite; PanelF->Color = clWhite; |
oder das:
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 |
A0->Caption = " "+IntToStr(bit[0][3])+" "+IntToStr(bit[0][2])+" "+IntToStr(bit[0][1])+" "+IntToStr(bit[0][0])+" "; A1->Caption = " "+IntToStr(bit[1][3])+" "+IntToStr(bit[1][2])+" "+IntToStr(bit[1][1])+" "+IntToStr(bit[1][0])+" "; A2->Caption = " "+IntToStr(bit[2][3])+" "+IntToStr(bit[2][2])+" "+IntToStr(bit[2][1])+" "+IntToStr(bit[2][0])+" "; A3->Caption = " "+IntToStr(bit[3][3])+" "+IntToStr(bit[3][2])+" "+IntToStr(bit[3][1])+" "+IntToStr(bit[3][0])+" "; A4->Caption = " "+IntToStr(bit[4][3])+" "+IntToStr(bit[4][2])+" "+IntToStr(bit[4][1])+" "+IntToStr(bit[4][0])+" "; A5->Caption = " "+IntToStr(bit[5][3])+" "+IntToStr(bit[5][2])+" "+IntToStr(bit[5][1])+" "+IntToStr(bit[5][0])+" "; A6->Caption = " "+IntToStr(bit[6][3])+" "+IntToStr(bit[6][2])+" "+IntToStr(bit[6][1])+" "+IntToStr(bit[6][0])+" "; A7->Caption = " "+IntToStr(bit[7][3])+" "+IntToStr(bit[7][2])+" "+IntToStr(bit[7][1])+" "+IntToStr(bit[7][0])+" "; A8->Caption = " "+IntToStr(bit[8][3])+" "+IntToStr(bit[8][2])+" "+IntToStr(bit[8][1])+" "+IntToStr(bit[8][0])+" "; ............. |
oder das auf jeden fall
|
|
Quellcode |
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 |
bit[0][0] = bit00->Checked; bit[0][1] = bit01->Checked; bit[0][2] = bit02->Checked; bit[0][3] = bit03->Checked; bit[1][0] = bit10->Checked; bit[1][1] = bit11->Checked; bit[1][2] = bit12->Checked; bit[1][3] = bit13->Checked; bit[2][0] = bit20->Checked; bit[2][1] = bit21->Checked; bit[2][2] = bit22->Checked; bit[2][3] = bit23->Checked; bit[3][0] = bit30->Checked; bit[3][1] = bit31->Checked; bit[3][2] = bit32->Checked; bit[3][3] = bit33->Checked; bit[4][0] = bit40->Checked; bit[4][1] = bit41->Checked; bit[4][2] = bit42->Checked; bit[4][3] = bit43->Checked; ....... |
gReEtZ bY traZor
Sehn wir uns das mal an einem anderen Beispiel an. Nur zum vergleich. Ich denke, wenn du es mir daran konkret zeigst, dann hab ich es vollends.
Nehmen wir mal an, ich hab in einem Formular viele verschiedene Labels. Diese Labels haben Namen, die so aussehen:
Label_1
Label_2
Label_3
Label_4
...
Label_20
Ist es möglich den Labels mithilfe einer Schleife (nicht allen auf einmal) eine gleichen Caption Wert zuzuweisen?
Wenn ja, dann zeige es mir bitte konkret mit einem für dieses Beispiel funktionierenden Quelltext =)
Danke schonmal
Nehmen wir mal an, ich hab in einem Formular viele verschiedene Labels. Diese Labels haben Namen, die so aussehen:
Label_1
Label_2
Label_3
Label_4
...
Label_20
Ist es möglich den Labels mithilfe einer Schleife (nicht allen auf einmal) eine gleichen Caption Wert zuzuweisen?
Wenn ja, dann zeige es mir bitte konkret mit einem für dieses Beispiel funktionierenden Quelltext =)
Danke schonmal
gReEtZ bY traZor
Hi
Also ich habe auch nicht so viel Ahnung von C++, aber diesen Bereich hier, denke ich, kann man nicht verkürzen, da er noch Buchstaben drin hat.
Die anderen beiden sollte man doch leicht mit einer for-schleife machen, oder?
Mfg Fab
Also ich habe auch nicht so viel Ahnung von C++, aber diesen Bereich hier, denke ich, kann man nicht verkürzen, da er noch Buchstaben drin hat.
Zitat
Panel0->Color = clWhite;
Panel1->Color = clWhite;
Panel2->Color = clWhite;
Panel3->Color = clWhite;
Panel4->Color = clWhite;
Panel5->Color = clWhite;
Panel6->Color = clWhite;
Panel7->Color = clWhite;
Panel8->Color = clWhite;
Panel9->Color = clWhite;
PanelA->Color = clWhite;
PanelB->Color = clWhite;
PanelC->Color = clWhite;
PanelD->Color = clWhite;
PanelE->Color = clWhite;
PanelF->Color = clWhite;
Die anderen beiden sollte man doch leicht mit einer for-schleife machen, oder?
Mfg Fab
-->Vokaline - schneller und effizienter Wörter lernen<-- (kostenlos!)
lassen wir doch die blöden buchstaben weg, die kann ich ändern. sag mir nur, wie das mit ner schleife gehen soll: es geht nämlich nicht. man müsste nämlich zur laufzeit den eingesetzten variablennamen ädern... aber das geht nicht! also wie geht's denn??? JETZT NUR AUF MEIN NEUES BEISPIEL BEZOGEN!!!
gReEtZ bY traZor


