Autor Beitrag
pHaRyNx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Fr 27.01.06 20:33 
ich habe mal wieder ein problem:
ich möchte 5 variablen mit 5 verschiedenen strings(bzw. anderen variablen) vergleichen. das hieße jedoch, dass ich 5^5 möglichkeiten hätte, also müsste ich 5^5 zeilen (mit if oder OR...) schreiben, doch das ist mir eindeutig zu viel! kann man diese sache irgendwie vereinfachen? (eine möglichkeit unter 20 zeilen wäre mir genehm)
bitte schreibt, wenn ihr eine lösung für mein problem habt.
mfg pHaRyNx
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Fr 27.01.06 20:44 
ich könnte dir (wenn ich wollte) eine komplett fertige Lösung liefern, die unendlich viele Wörter vergleichen kann. Allerdings würdest du dann selbst kaum überlegen, oder?
Ich gebe dir mal einen Denkanstoß:
Du kennst sicherlich StringLists, davon nimm mal zwei.
Dann sollte man das x. Item der 1. StringList mit jedem Item der zweiten StringList vergleichen.
So werden alle Möglichkeiten überprüft.


Zuletzt bearbeitet von Danniolo am Sa 04.02.06 15:58, insgesamt 1-mal bearbeitet
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 27.01.06 22:51 
Oder, wenn es immer genau 5 Strings sind, geht das auch mit Konstanten:
ausblenden Delphi-Quelltext
1:
2:
3:
Const
  A : Array [0..4] of String = ('Eins','Noch eins','Drei','Vorletztes','Fertig');
  B : Array [0..4] of String = ....

_________________
Na denn, dann. Bis dann, denn.
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 765
Erhaltene Danke: 130



BeitragVerfasst: Sa 28.01.06 18:22 
Such mal im Internet nach Bubblesort. Das ist zwar nicht besonders schnell, aber bei 5 Zahlen ist das wohl egal.
Dann bleibst Du auch unter 20 (oder auch unter 10) Zeilen.
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Di 31.01.06 13:59 
Wie genau liege die Variablen vor? Alle einzeln definiert oder zum Beispiel ein Array?

_________________
Ein Nutzer der Ecke ;-)
pHaRyNx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Sa 04.02.06 13:57 
ja, einzeln, aber ich habs jetzt mit dem stringlistenvergleich gelöst (danke an Danniolo für den hilfreichen denkanstoß). so wie versprochen jetzt hier der fertige quelltext meines vokabeltrainers:
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:
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:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    ComboBox1: TComboBox;
    Edit3: TEdit;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Label3: TLabel;
    Button3: TButton;
    Label4: TLabel;
    Label5: TLabel;
    Timer1: TTimer;
    LabelE: TLabel;
    Edit4: TEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}
var filename:String;
    nr,richtig,lastpos:Integer;
    StringListE,StringListD, StringListD1,StringListD2,StringListD3,StringListD4,StringListD5:TStrings;
const ver='Vokabeltrainer 1.0';



procedure TForm1.Button2Click(Sender: TObject);
var 
    i,i2,x,x1,x2,z:Integer;
    StringListXXX:TStrings;
    str,fake:String;
    t1,t2,q1,q2,q3,q4,q5:String;//q ist für die D1-D5-StringListeneinträge
begin
filename:='';
if OpenDialog1.Execute=true then
  begin
  filename:=OpenDialog1.FileName;
  Edit3.Text:=filename;
  end
  else exit;
if filename<>'' then Label4.Visible:=True
  else Label4.Visible:=False;

StringListE:=TStringList.Create;
StringListD:=TStringList.Create;
StringListD1:=TStringList.Create;
StringListD2:=TStringList.Create;
StringListD3:=TStringList.Create;
StringListD4:=TStringList.Create;
StringlistD5:=TStringList.Create;
StringListXXX:=TStringList.Create;

StringListE.Clear;
StringListD.Clear;
StringListD1.Clear;
StringListD2.Clear;
StringListD3.Clear;
StringListD4.Clear;
StringListD5.Clear;
StringListXXX.Clear;

StringListXXX.LoadFromFile(filename);

for i:=0 To StringListXXX.Count-1 Do
  begin
  t1:='';
  t2:='';
  q1:='';
  q2:='';
  q3:='';
  q4:='';
  q5:='';
  fake:='';
  str:=StringListXXX[i];
  x:=pos(';',str);
  x1:=x-1;
  x2:=x+1;
    for i2:=1 To x1 Do
    begin
    t1:=t1+str[i2];
    //Label3.Caption:=t1;
    end;

    for i2:=x2 To length(str) Do
    begin
    t2:=t2+str[i2];
    //Label3.Caption:=t2;
    end;
   //ShowMessage(t1);
   StringListE.Add(t1);
   StringListD.Add(t2);
     if pos(',',t2)=0 then
       begin
   StringListD1.Add(t2);
       StringListD2.Add('xyxx');
       StringListD3.Add('xyxx');
       StringListD4.Add('xyxx');
       StringListD5.Add('xyxx');
       end
         else
         begin
         fake:=Copy(t2,(pos(',',t2)+1),length(t2));
         q1:=Copy(t2,1,(pos(',',t2)-1));
     StringListD1.Add(q1);

           if pos(',',fake)=0 then
           begin
           StringListD2.Add(fake);
           StringListD3.Add('xyxx');
           StringListD4.Add('xyxx');
           StringListD5.Add('xyxx');
           end
            else 
            begin
            fake:=Copy(t2,(pos(',',t2)+1),length(t2));
            q2:=Copy(fake,1,(pos(',',fake)-1));
            StringListD2.Add(q2);
            end;

             if pos(',',fake)=0 then
             begin
             StringListD3.Add(fake);
             StringListD4.Add('xyxx');
             StringListD5.Add('xyxx');
             end
              else
              begin
              fake:=Copy(fake,(pos(',',fake)+1),length(fake));
              q3:=Copy(fake,1,(pos(',',fake)-1));
              StringListD3.Add(q3);
              end;

             if pos(',',fake)=0 then
             begin
             StringListD4.Add(fake);
             StringListD5.Add('xyxx');
             end
              else
              begin
              fake:=Copy(fake,(pos(',',fake)+1),length(fake));
              q4:=Copy(fake,1,(pos(',',fake)-1));
              StringListD4.Add(q4);
              end;

             if pos(',',fake)=0 then
             begin
             fake:=Copy(fake,(pos(',',fake)+1),length(fake));
             q5:=fake;
             StringListD5.Add(q5);
             end
              else
              begin
              fake:=Copy(fake,(pos(',',fake)+1),length(fake));
              q5:=fake;
              StringListD5.Add(q5);
              end;

         end;

{....->reststring (ohne qX) zwischenspeichern, danach weiter nach komma suchen und maßnahme wiederholen, sonst xxx eintrag in entsprechende stringlist tätigen. }        


     end;


Randomize;
z:=random(StringListXXX.Count);

for i:=0 To StringListXXX.Count-1 Do
  begin
  StringListE.Move(i,z);
  StringListD.Move(i,z);
  StringListD1.Move(i,z);
  StringListD2.Move(i,z);
  StringListD3.Move(i,z);
  StringListD4.Move(i,z);
  StringListD5.Move(i,z);
  end;

StringListXXX.Free;




//StringListE.Free;
//StringListD.Free;
Combobox1.Enabled:=True;
nr:=0;
richtig:=0;
Button3.Caption:='Start';
Button3.Enabled:=True;
LabelE.Visible:=False;
Button1.Enabled:=False;
end;


procedure TForm1.Button3Click(Sender: TObject);
var mss,mssnote:Integer;
begin
ComboBox1.Enabled:=False;
Button1.Enabled:=True;
Label3.Caption:='';
Edit2.Clear;
Edit4.Clear;
Edit2.SetFocus;
if nr > StringListE.Count-1 then
 begin
 mss:=round((richtig/nr)*100);
   case mss of
  95..100: mssnote:=15;
  90..94: mssnote:=14;
  85..89: mssnote:=13;
  80..84: mssnote:=12;
  75..79: mssnote:=11;
  70..74: mssnote:=10;
  65..69: mssnote:=9;
  60..64: mssnote:=8;
  55..59: mssnote:=7;
  50..54: mssnote:=6;
  45..49: mssnote:=5;
  40..44: mssnote:=4;
  35..39: mssnote:=3;
  30..34: mssnote:=2;
  25..29: mssnote:=1;
  0..24:  mssnote:=0;
  end;
  LabelE.Visible:=True;
  LabelE.Caption:='Statistik:'#13'Gesamtanzahl der Vokabeln: '+IntToStr(nr)+#13'davon richtig: '+IntToStr(richtig)+#13'Fehler: '+IntToStr(nr-richtig)+#13#13'Prozent (richtig): '+IntToStr(mss)+' %'+#13#13'MSS-Punkte: '+IntToStr(mssnote);
  Button1.Enabled:=False;
  Button3.Enabled:=False;
  exit;
 end
  else
   begin
     if Combobox1.text='FS - Deutsch' then
       begin
       Label1.Caption:='FS';
       Edit1.Text:=StringListE[nr];
       end
        else
         begin
         Label1.Caption:='Deutsch';
         Edit1.Text:=StringListD[nr];
         end;
     Button3.Caption:='nächste Vokabel';
     INC(nr);
   Label5.Caption:='Nr. '+IntToStr(nr)+'/'+IntToStr(StringListE.Count);
 end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   Form2:=TForm2.Create(self);
   try
      Form2.ShowModal;
   finally
      Form2.Free
   end;

Button3.Enabled:=False;
Button1.Enabled:=False;
ComboBox1.Text:='FS - Deutsch';
Form1.Caption:=ver;
Label3.Caption:='';
Label1.Caption:='FS';
Lastpos:=1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var ed1,ed2,ed3,ed4,ed5,zspeicher:String;
    TEstSTringList:TStrings;
    i:Integer;
begin
Button1.Enabled:=False;
ComboBox1.Enabled:=True;
if pos(',',Edit2.Text)<>0 then
begin
ed1:=Copy(Edit2.Text,1,(pos(',',Edit2.Text)-1));
zspeicher:=Copy(Edit2.Text,(pos(',',Edit2.Text)+1),length(Edit2.Text));

ed2:=Copy(zspeicher,1,(pos(',',zspeicher)-1));
zspeicher:=Copy(zspeicher,(pos(',',zspeicher)+1),length(zspeicher));

ed3:=Copy(zspeicher,1,(pos(',',zspeicher)-1));
zspeicher:=Copy(zspeicher,(pos(',',zspeicher)+1),length(zspeicher));

ed4:=Copy(zspeicher,1,(pos(',',zspeicher)-1));
zspeicher:=Copy(zspeicher,(pos(',',zspeicher)+1),length(zspeicher));

ed5:=zspeicher;

TestSTringList:=TStringList.Create;
TestStringList.Clear;

TestSTringList.Add(ed1);
TestSTringList.Add(ed2);
TestSTringList.Add(ed3);
TestSTringList.Add(ed4);
TestSTringList.Add(ed5);
end
else
begin
TestSTringList:=TStringList.Create;
TestStringList.Clear;

TestSTringList.Add(Edit2.Text);
TestSTringList.Add(Edit2.Text);
TestSTringList.Add(Edit2.Text);
TestSTringList.Add(Edit2.Text);
TestSTringList.Add(Edit2.Text);
end;

for i:=0 to 4 Do
begin

if ComboBox1.Text='FS - Deutsch' then
 begin
if (CompareText(TestStringList[i],StringListD[nr-1])=0) OR ((CompareText(StringListD1[nr-1],TestStringList[i]))=0) OR ((CompareText(StringListD2[nr-1],TestStringList[i]))=0) OR ((CompareText(StringListD3[nr-1],TestStringList[i]))=0) OR ((CompareText(StringListD4[nr-1],TestStringList[i]))=0) OR ((CompareText(StringListD5[nr-1],TestStringList[i]))=0) then
  begin

  Edit4.Text:=StringListD[nr-1];
  INC(richtig);
  Label3.Font.Color:=clgreen;
  Label3.Caption:='richtig';
  exit;
  end
    else
     begin
     Edit4.Text:=StringListD[nr-1];
     Label3.Font.Color:=clred;
     Label3.Caption:='falsch';
     exit;
     end;
  //end;
 end
   else//wenn FS - Englisch
   begin
   if CompareText(StringListE[nr-1],Edit2.Text) = 0 then
   begin
   Edit4.Text:=StringListE[nr-1];
   INC(richtig);
   Label3.Font.Color:=clgreen;
   Label3.Caption:='richtig';
   exit;
   end
    else
     begin
     Edit4.Text:=StringListE[nr-1];
     Label3.Font.Color:=clred;
     Label3.Caption:='falsch';
     exit;
     end;
end;

//TestStringList.Free;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Form2.Close;
Timer1.Enabled:=False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
     if Combobox1.text='FS - Deutsch' then
       begin
       Label1.Caption:='FS';
       end
        else
         begin
         Label1.Caption:='Deutsch';
         end;
end;
//copyright by pHaRyNx !
end.

danke an alle, die mir geholfen haben, besonderer dank an Danniolo für die weiterführenden tipps.
mfg pHaRyNx
pHaRyNx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Do 16.03.06 17:09 
hallo!
ich habe doch noch einen bug in meinem programm gefunden und daher habe ich eine neue prozedur geschrieben, weil ich den alten quelltext zu kompliziert fand:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure cutter(s:String;var s2,restString:String);
begin

if pos(',',s)=0 then 
  begin
   restString:=s;
   s2:=s;
  end
  else
   begin
   s2:=Copy(s,1,(pos(',',s)-1));
   restString:=Copy(s,(pos(',',s)+1),length(s));
   end;
end;

Delphi meckert jedoch bei folgendem prozedur aufruf:
ausblenden Delphi-Quelltext
1:
cutter(t2);//t2 ist ein String					

und es kommt diese fehlermeldung:
Zitat:

[Error] Unit1.pas(133): Not enough actual parameters


könnt ihr mir helfen?
mfg pHaRyNx
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Do 16.03.06 17:12 
die procedure erwartet 2 Parameter.. das heißt, du solltest beim Aufruf auch 2 davon angeben :mrgreen:
pHaRyNx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Do 16.03.06 17:40 
ausblenden Delphi-Quelltext
1:
procedure cutter(s:String;var s2,restString:String);					

ich versteh garnix mehr. erwartet die prozedur nicht nur den string 's' ???
selbst wenn, ich habe jetzt
ausblenden Delphi-Quelltext
1:
cutter(t2,t2);					

probiert, und dasselbe passiert.
die var s2 und restString sind doch diejenigen, die von der prozedur zurückgegeben werden, oder irre ich mich?
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 16.03.06 17:50 
probiers mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure cutter(s:String);
var s2,restString: String;
begin
 if pos(',',s)=0 then
  begin
   restString:=s;
   s2:=s;
  end
  else
   begin
   s2:=Copy(s,1,(pos(',',s)-1));
   restString:=Copy(s,(pos(',',s)+1),length(s));
  end;
end;

;)

du irrst dich nicht, aber die variablen, die du oben hinter 'procedure' angegeben hast sind parameter, die beim aufruf der funktion festgelegt werden müssen ;)
hoffe das stimmt so :roll:

aufrufen tust du die procedure nun so:
ausblenden Delphi-Quelltext
1:
2:
3:
begin
 cutter(s); // s ist irgend ein text, zb. memo1.text, label1.caption, was weiß ich, was du vorhast (:
end;
pHaRyNx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 94

win 95, win 2000, win xp, VISTA, Ubuntu 8.04
Delphi 7 PE
BeitragVerfasst: Sa 18.03.06 14:47 
vielen dank. kann man im prinzip dann eigentlich die var s2 und restSTring weglassen, wenn die variablen globale sind, oder macht das einen unterschied?
mfg pHaRyNx