Autor Beitrag
DelphiInLove
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 20.02.09 15:38 
Hi Leute hab ein problem mit nem Programm:
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:
unit Dreck;

interface

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

type
  TForm1 = class(TForm)
    Label4: TLabel;
    Label7: TLabel;
    Button1: TButton;
    StringGrid1: TStringGrid;
    OpenDialog1: TOpenDialog;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
j:integer;
begin
for j:=1 to StringGrid1.RowCount do
begin
  StringGrid1.Cells[0,j]:=IntToStr(j);
end;

for j:=1 to StringGrid1.RowCount do
begin
  StringGrid1.Cells[1,j]:=IntToStr(0);
end;

StringGrid1.Cells[0,0]:='Kandidat';
StringGrid1.Cells[1,0]:='Stimmen absolut';
StringGrid1.Cells[2,0]:='Stimmen relativ';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
textdatei:textfile;
zeile:string;
i,j,kan,anz,u,z,k:integer;
a: array[1..10of real;
rolloe:real;
begin
if OpenDialog1.Execute then
  begin
    AssignFile(textdatei,opendialog1.filename);
    reset(textdatei);
    anz:=0;
    repeat
    anz:=anz+1;
    readln(textdatei,zeile);
    kan:=StrToInt(copy(zeile,11,1));
    if kan=1 then
      begin
        if length(zeile)=12 then

            StringGrid1.cells[1,10]:=IntToStr(StrToInt(StringGrid1.Cells[1,10])+1)
            else
            StringGrid1.Cells[1,1]:=IntToStr(StrToInt(StringGrid1.Cells[1,1])+1);
      end;
     for i:=2 to 9 do
     begin
     if StrToInt(StringGrid1.Cells[0,i])=kan then
        StringGrid1.Cells[1,i]:=IntToStr(StrToInt(StringGrid1.Cells[1,i])+1);
        end;
    until EOF(textdatei);

    for k:=1 to 10 do
    a[k]:=strtoint(stringgrid1.Cells[1,k]);


    label7.Caption:=inttostr(anz);
    for i:=1 to stringgrid1.RowCount do
        stringgrid1.Cells[2,i]:=floattostrf(100*strtoint(stringgrid1.cells[1,i])/anz,fffixed,7,2);

     for u:=1 to 10 do     // Uhr bleibt stehen n
     begin
        for z:=1 to 10  do          // die Uhr geht weiter   n+10
        begin
         if a[u]>a[z] then
          begin rolloe:=a[u] ;
          a[u]:=a[z];
          a[z]:=rolloe;
          end;
          end;
          for j:=1 to 10 do
          begin
            if stringgrid1.Cells[1,j]=floattostr(a[1]) then
            begin
            edit1.Text:=stringgrid1.Cells[0,j];
            edit1.Width:=strtoint(stringgrid1.cells[2,j]);
            end;

            if stringgrid1.Cells[1,j]=floattostr(a[2]) then
            begin
            edit2.Text:=stringgrid1.Cells[0,j];
            edit2.Width:=strtoint(stringgrid1.cells[2,j]);
            end;

            if stringgrid1.Cells[1,j]=floattostr(a[3]) then
            begin
            edit3.Text:=stringgrid1.Cells[0,j];
            edit3.Width:=strtoint(stringgrid1.cells[2,j]);

            end;
            end;

    end;
end;
end;


end.

jedes Mal wenn ich das ausführe kommt die Fehlermeldung:
Im Project Project1.exe ist eine Exeption der Klasse EConvertError aufgetreten."11,11" ist kein gültiger Integerwert
die Datei die ich einlese ist im Anhang.

Moderiert von user profile iconGausi: Quote- durch Delphi-Tags ersetzt
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von DelphiInLove am Fr 20.02.09 15:47, insgesamt 1-mal bearbeitet
Dude566
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1592
Erhaltene Danke: 79

W8, W7 (Chrome, FF, IE)
Delphi XE2 Pro, Eclipse Juno, VS2012
BeitragVerfasst: Fr 20.02.09 15:42 
Pack dein Quelltext lieber in [delphi] als [quote], ist besser zu lesen. :wink:

_________________
Es gibt 10 Gruppen von Menschen: diejenigen, die das Binärsystem verstehen, und die anderen.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 20.02.09 15:45 
  1. Ändere bitten den Titel deines Beitrags, Hilfe braucht hier jeder.
  2. Delphi liegt richtig, 11,11 ist auch kein gültiger Integerwert. Was du brauchst, ist eine Fließkommazahl, zum Beispiel Single oder Double.
DelphiInLove Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 20.02.09 15:49 
aber alles was mit dieser 11,11 zusammenhängt hab ich doch als real gemacht also müssten doch auch Kommazahlen gehen??

MfG DelphiInLove
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 20.02.09 15:52 
Du benutzt aber StrToInt an der Stelle offensichtlich. ;-)
Welche das ist, solltest du mit dem Debugger leicht herausfinden können.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 20.02.09 15:53 
user profile iconDelphiInLove hat folgendes geschrieben Zum zitierten Posting springen:
aber alles was mit dieser 11,11 zusammenhängt hab ich doch als real gemacht also müssten doch auch Kommazahlen gehen??

Ohne jetzt den gesamten Quelltext durchzugehen (in welcher Zeile tritt denn der Fehler auf?), würde ich tippen, du versuchst die Zahl mit IntToStr umzuwandeln. Da bringt es nichts, dass die Zielvariable ein Real ist (der übrigens schon veraltet ist - nimm lieber Single oder Double). Verwende stattdessen FloatToStr - die kommt auch mit Gleitkommazahlen zurecht.

Ach ja, ich seh's erst jetzt: :welcome: im Delphi-Forum, user profile iconDelphiInLove!
DelphiInLove Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 20.02.09 15:55 
der Debugger zeigt leider keine Fehler an... :(
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Fr 20.02.09 16:07 
user profile iconYogu hat folgendes geschrieben Zum zitierten Posting springen:
würde ich tippen, du versuchst die Zahl mit IntToStr umzuwandeln.

Du meinst sicher andersrum, StrToInt ;)

Zu deinem Problem: Äh.. ich seh nur noch StrToInt und IntToStr und StrToFloat und was weiß ich nicht alles..
Blickst du da eigentlich noch durch? Normalerweise sagt man ja, man soll Daten und Anzeige trennen. :D Also, die Daten in Variablen, Arrays oder Records halten, DAMIT dann arbeiten, und nur noch die Ergebnisse in die Ausgabekomponenten (in deinem Fall das StringGrid) schreiben.

_________________
PROGRAMMER: A device for converting coffee into software.
DelphiInLove Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 20.02.09 16:08 
ich glaub ich hab meinen fehler gefunden:
Ich will ja das die Länge der Edit Felder den Prozent angepasst wird,da die Prozent aber Kommazahlen sind(u.a. die 11,11) funktioniert das nicht.Kann ich diese Prozenzahlen runden lassen so das sie dann auch in das Edit.Width eingetragen werden können??

MfG DIL
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Fr 20.02.09 16:11 
user profile iconDelphiInLove hat folgendes geschrieben Zum zitierten Posting springen:
ich glaub ich hab meinen fehler gefunden:
Ich will ja das die Länge der Edit Felder den Prozent angepasst wird,da die Prozent aber Kommazahlen sind(u.a. die 11,11) funktioniert das nicht.Kann ich diese Prozenzahlen runden lassen so das sie dann auch in das Edit.Width eingetragen werden können??

Hm, was für einen Befehl könnte man wohl zum Runden verwenden.. *wörterbuch aufschlag* Ah, "round". Schon fast zu einfach ;)

_________________
PROGRAMMER: A device for converting coffee into software.
DelphiInLove Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 20.02.09 16:16 
HAHA...es funktioniert^^
Danke für eure schnelle Hilfe

MfG DelphiInLove
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Fr 20.02.09 16:18 
[quote="user profile iconDelphiInLove"(550446)Danke für eure schnelle Hilfe[/quote]
Trotzdem solltest dir meinen vorletzten Beitrag nochmal durchlesen, und das ein wenig trennen.

_________________
PROGRAMMER: A device for converting coffee into software.