Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Inkompatible Typen 'string' und 'Integer'


mara_buh - Mi 31.05.06 18:57
Titel: Inkompatible Typen 'string' und 'Integer'
Hallo alle zusammen...
ich hab mal wieder einen fehler gemacht, aber ich kann ihn leider nicht selbst korrigieren. Jedes mal, wenn ich auf start drücke, kommt die meldung: "Inkompatible Typen 'string' und 'integer'". Kann mir vllt irgendjemand sagen, was ich verändern muss, damit diese Meldung nicht mehr erscheint??

Herzlichen dank!!
mara_buh

Quelltext:


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:
procedure TForm1.Button4Click(Sender: TObject);
var min,max,min2,min3,min4,positi,posit,positio,j,g,i,f,h,posi,pos: integer;
begin
with listbox1 do
 begin
 min:=StrToInt(Items[0]);
 Pos:=0;
 for i:=1 to Items.count-1 do
 begin
   if StrToInt(Items[i]) <= min then
   begin
   min:=StrToInt(Items[i]);
   pos:=i;
   end;
   if strtoint(items[i] > min then
   items[0]:=inttostr(min);
  end
     Items[i]:=Items[0];
   Items[0]:=inttostr(min);
   Items.Delete(pos);
  end;

{ with listbox1 do
 begin
 min2:=Strtoint(items[1]);
 posit:=1;
 for g:=2 to items.count-1 do
  if strtoint(items[g]) <= min2 then
  begin
  min2:=StrToInt(Items[g]);
  posit:=g;
  end;
Items[g]:=Items[1];
Items[1]:=inttostr(min2);
Items.Delete(posit);
 end;
 with listbox1 do
 begin
 min3:=Strtoint(items[2]);
 positi:=2;
 for h:=3 to items.count-1 do
  if strtoint(items[h]) <= min3 then
  begin
  min3:=StrToInt(Items[h]);
  positi:=h;
  end;
Items[h]:=Items[2];
Items[2]:=inttostr(min3);
Items.Delete(positi);
 end;
 with listbox1 do


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt


Delete - Mi 31.05.06 19:07

welche zeile denn?


der Berliner - Mi 31.05.06 19:08

Hallo

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Button4Click(Sender: TObject);   
var min,max,min2,min3,min4,positi,posit,positio,j,g,i,f,h,posi,pos: integer;   
begin   
with listbox1 do   
 begin   
 min:=StrToInt(Items[0]);   
 Pos:=0;   
 for i:=1 to Items.count-1 do   
 begin   
   if StrToInt(Items[i]) <= min then   
   begin   
   min:=StrToInt(Items[i]);   
   pos:=i;   
   end;   
   if strtoint(items[i]) > min then   // <----Hier fehlt bei dir die Klammer
   items[0]:=inttostr(min);   
  end;    
     Items[i]:=Items[0];   
   Items[0]:=inttostr(min);   
   Items.Delete(pos);   
  end;

Gruß


mara_buh - Mi 31.05.06 21:38

ach ja ...danke
ich hab den quelltext nochma überarbeitet. Das programm gibt 5 zufallszahlen in einer listbox aus. wenn man auf nen button klickt ordnen sich die Zahlen. jetz gibt´s nur noch ein Problem. und zwar: wenn eine zahl schon zufällig an der richtigen stelle der geordneten reihenfolge steht, funktioniert das ganze irgendwie nich. das heißt, die zahö bleibt nich an der stelle sondern verschiebt sich irgendwie an das ende der ganzen reihenfolge. hat jemand ne ahnung, wie ich das problem beheben kann???

liebe Grüße
mara_buh

quelltext:


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:
procedure TForm1.Button1Click(Sender: TObject);
var a, b, c, d, e: integer;
begin
randomize;
a:=Random(100)+1;
b:=Random(100)+1;
c:=Random(100)+1;
d:=Random(100)+1;
e:=Random(100)+1;

ListBox1.Items.Add(IntToStr(a));
ListBox1.Items.Add(IntToStr(b));
ListBox1.Items.Add(IntToStr(c));
ListBox1.Items.Add(IntToStr(d));
ListBox1.Items.Add(IntToStr(e));


end;

procedure TForm1.Button4Click(Sender: TObject);
var min,max,min2,min3,min4,positi,posit,positio,j,g,i,f,h,posi,pos: integer;
begin
with listbox1 do
 begin
 min:=StrToInt(Items[0]);
 Pos:=0;
 for i:=1 to Items.count-1 do
  if StrToInt(Items[i]) <= min then
    begin min:=StrToInt(Items[i]) ;
          pos:=i;
    end;
      Items[i]:=Items[0];
      Items[0]:=inttostr(min);
      Items.Delete(pos);
  end;

with listbox1 do
 begin
 min2:=Strtoint(items[1]);
 posit:=1;
 for g:=2 to items.count-1 do
  if strtoint(items[g]) <= min2 then
  begin
  min2:=StrToInt(Items[g]);
  posit:=g;
  end;
Items[g]:=Items[1];
Items[1]:=inttostr(min2);
Items.Delete(posit);
 end;
 with listbox1 do
 begin
 min3:=Strtoint(items[2]);
 positi:=2;
 for h:=3 to items.count-1 do
  if strtoint(items[h]) <= min3 then
  begin
  min3:=StrToInt(Items[h]);
  positi:=h;
  end;
Items[h]:=Items[2];
Items[2]:=inttostr(min3);
Items.Delete(positi);
 end;
 with listbox1 do
 begin
 min4:=Strtoint(items[3]);
 positio:=3;
 for j:=4 to items.count-1 do
  if strtoint(items[j]) <= min4 then
  begin
  min4:=StrToInt(Items[j]);
  positio:=j;
  end;
Items[j]:=Items[3];
Items[3]:=inttostr(min4);
Items.Delete(positio);
 end;
 with listbox1 do
 begin
 max:=strToInt(Items[0]);
 posi:=0;
 for f:=0 to Items.count-1 do
  if strtoint(items[f]) >= max then
  begin
  max:=StrToInt(Items[f]);
  posi:=f;
  end;
Items.Delete(posi);
Items.Add(Inttostr(max))
 end
 end;


Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt