Autor Beitrag
Hazer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Fr 18.03.05 23:01 
Hi,
habe mal'ne Frage.
Wie kann es sein, dass mein Programm einfach durchläuft und sich dann am ende schließt (Rede ist von einer Konsolen Aplikation)
Obwohl ich am Ende genau vor end. ein readln; zu stehen habe.
Hier der Code (Alles andere nicht beachten! ;))
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:
program rechner;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  s,d,a1,a2,op1,op2,operation:string;
  c:integer;
begin
  writeln('Willkommen bei "compute you stupid V1.0 Beta"');
  writeln('Gebe nun deine Funktion ein, die berechnet werden soll!',chr(266));
  readln(s);
  d:=s;
  if (ord(d[1]) < 58AND (ord(d[1]) > 44then begin
     c:=0;
     repeat
        c:=c+1;
        if not (((ord(d[c]) < 58AND (ord(d[c]) > 47)) OR (ord(d[c]) = 46)) then begin;
           if a1='' then a1:=copy(d,1,c-1)
           else a2:=copy(d,1,c-1);
           if ord(d[c])+ord(d[c+1])+ord(d[c+2]) > 161 then begin
              delete(d,1,c-1);
              if a2='' then op1:=copy(d,1,3)
              else op2:=copy(d,1,3);
              delete(d,1,3);
           end;
           if ord(d[c])+ord(d[c+1])+ord(d[c+2]) < 161 then begin
              delete(d,1,c-1);
              operation:=copy(d,1,1);
              delete(d,1,1);
           end;
        end;
     until c = length(d);
  end;
  write(a2);
  readln;
end.


Es kommt keine Fehlermldung oder Sonstiges. Es läfut bis readln(s); normal durch. Dann gebe ich die Funktion ein und schwupss, sehe ich kurz wie unten noch a2 ausgegeben wird und schon ist das Ding wieder zu ;(
Als ob das readln; am Ende nicht zählen würde ;( Woran liegt das? Ist mir glaube ich schoneinmal passiert. Da hab ich dann einfach den ganzen Code nochmal abgeschrieben :shock:

Erstaunlich ist, dass, wenn ich die ganze If-Anweisung als Kommentar schreibe, dass dann alles glatt läuft. o.0? Aber ich verstehe einfach nicht warum :evil:

Danke schonmal für die Hilfe^^"
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Fr 18.03.05 23:36 
vielleicht musste vor dem readln ein writeln machen oder ne variable bei readln angeben

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Fr 18.03.05 23:39 
Mach mal ein try..finally..end drum herum. Es gibt bestimmt irgendwo nen Fehler.
//Edit: Access Violation auf Zeile 19.
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Sa 19.03.05 00:25 
Stimmt bei try finally end kommt tatsächlich das Programm bis readln;

Doch stellt Sich mir jetzt die frage, was am code falsch ist o.0?
Und was bedeutet Zugriffsverletzung in Zeile 19?
Wie kann ich das bereinigen?


Zuletzt bearbeitet von Hazer am Sa 19.03.05 00:30, insgesamt 1-mal bearbeitet
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 19.03.05 00:27 
Ganz einfach: du greifst auf das c-te Zeichen von d (s) zu, ohne dich zu vergewissern, dass das d überhaupt ein c-tes Zeichen hat...

AXMD
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Sa 19.03.05 00:37 
:shock: :?:
Wie? Das geht nicht?
Mein schönes Programm... es hat kein Sinn mehr :( :cry:

Hat jemand eine idee, wie ich das praktich umsetzen kann?
Sollte ich immer vorher nachfragen ob es ein c-tes Zeichen gibt?

Bsp.:
ausblenden Quelltext
1:
if length(d)<=c then...					

:?:
Oder verstehe ich das falsch?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 19.03.05 00:40 
Wieso einfach wenn's auch kompliziert geht :lol:

Mach doch einfach eine for- anstatt einer repeat-Schleife; da die for-Schleife kopfgesteuert ist stellst du sicher, dass die Schleife nicht durchlaufen wird, wenn Length(d) <= c ;).

AXMD
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Sa 19.03.05 00:43 
Na, ich Depp :oops:

Danke ;)
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Sa 19.03.05 18:39 
habe damit mal weiter gearbeitet und bin wieder da, wo ich vorher war ;(

Der einzigste Unterschied das Programm funktioniert. Aber leider nur, wenn ich try finally end; benutze :cry:
ich habe schon verschiedenes probiert, damit es läuft, bei einem war sogar nur der Unterschied von einem </> zu 'groß' dass es funktionierte. Ich habe echt kein plan, wie man das 'handling' muss.
wonach muss ich ausschau halten und wie komm ich auf die angesprochene Fehlermeldung, wie sie delphiphan bekommen hat?

Mist, ich komm mir jetzt richtig dumm vor... :cry:
Wäre nett, wenn ihr noch mal kucken könntet und mir meine Dummheit verzeihen :?

Hier der code
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:
program rechner;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  s,d,a1,a2,op1,op2,operation:string;
  c,b:integer;
begin
 readln(s);
  d:=s;
  b:=0;
  c:=1;     try
  if (ord(d[1]) < 58AND (ord(d[1]) > 44then begin;
     while c <= length(d) do begin;
        b:=b+1;
        if (ord(d[c]) > 57OR (ord(d[c]) < 48)then begin;
           if (length(a1)=0OR (length(a2)=0OR (length(op1)=0OR (length(op2)=0then begin;
              if length(a1)=0 then a1:=copy(d,0,b-1)
              else a2:=copy(d,0,b-1);
              if not (a2=''then begin
                 if ord(d[b]) > 114 then begin;
                    op2:=copy(d,b,3);
                    delete(d,1,3);
                 end;
              end;
              delete(d,1,b-1);
              c:=c-b+1;
              b:=0;
             if (ord(d[c]) <= 47AND (ord(d[c]) <> 46)  AND (length(operation) = 0)then begin;
                 operation:=copy(d,0,1);
                 delete(d,1,1);
                 c:=c-1;
              end;
              if (ord(d[c+1])+ord(d[c+2]) < 115then begin;
                 if length(op1)=0 then op1:=copy(d,0,3);
                 delete(d,1,3);
                 c:=c-3;
              end;
           end;
        end;
     c:=c+1;
     end;
  end;             finally
  readln;                 end;
end.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 19.03.05 18:43 
Du solltest deinen Code mal sauberer formatieren, das sieht ja grauenvoll und unlesbar aus

AXMD
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Sa 19.03.05 18:59 
hier mal der Formatierte Quellcode:
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:
Program rechner;

{$APPTYPE CONSOLE}

Uses
    SysUtils;
Var
    S, D, a1, a2, op1, op2, Operation: String;
    C, B: Integer;
Begin
    ReadLn(S);
    D := S;
    B := 0;
    C := 1;
    Try
        If (Ord(D[1]) < 58And (Ord(D[1]) > 44Then
        Begin
            While C <= Length(D) Do
            Begin
                B := B + 1;
                If (Ord(D[C]) > 57Or (Ord(D[C]) < 48Then
                Begin
                    If (Length(a1) = 0Or (Length(a2) = 0Or (Length(op1) = 0Or (Length(op2) = 0Then
                    Begin
                        If Length(a1) = 0 Then
                            a1 := Copy(D, 0, B - 1)
                        Else
                            a2 := Copy(D, 0, B - 1);
                        If Not (a2 = ''Then
                        Begin
                            If Ord(D[B]) > 114 Then
                            Begin
                                op2 := Copy(D, B, 3);
                                Delete(D, 13);
                            End;
                        End;
                        Delete(D, 1, B - 1);
                        C := C - B + 1;
                        B := 0;
                        If (Ord(D[C]) <= 47And (Ord(D[C]) <> 46And (Length(Operation) = 0Then
                        Begin
                            Operation := Copy(D, 01);
                            Delete(D, 11);
                            C := C - 1;
                        End;
                        If (Ord(D[C + 1]) + Ord(D[C + 2]) < 115Then
                        Begin
                            If Length(op1) = 0 Then
                                op1 := Copy(D, 03);
                            Delete(D, 13);
                            C := C - 3;
                        End;
                    End;
                End;
                C := C + 1;
            End;
        End;
    Finally
        ReadLn;
    End;
End.


Warum hast du nach "begin" manchmal ein ";" gesetzt? Also bei mir läuft das Programm so, aber mir fehlt da irgendwie noch der sinn ;D

mfg matze

_________________
si tacuisses, philosophus mansisses.
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 19.03.05 19:04 
user profile iconmatze.de hat folgendes geschrieben:
Also bei mir läuft das Programm so, aber mir fehlt da irgendwie noch der sinn ;D
mfg matze


Ich frage mich generell, was dieses Programm überhaupt machen soll...

AXMD
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 19.03.05 19:19 
also mit matzes formatierung ist der source noch schwerer zu lesen als vorher...

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Hazer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54

Win XP Pro SP2
Turbo Delphi 2006
BeitragVerfasst: Sa 19.03.05 19:19 
hi,
sorry wegen der 'Unformatiertheit' :(
Also das mit dem begin hab ich so ina Schule gelernt. Aber na ja nicht so wichtig.
Der Sinn ist erstmal egal, da es nur ein kleiner Teil eines Programms wird 8)

Aber mein Problem ist, dass ich es ohne try finally end; haben muss.
So schreibt's jedenfalls mein Lehrer vor :evil:
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Sa 19.03.05 19:26 
user profile iconretnyg hat folgendes geschrieben:
also mit matzes formatierung ist der source noch schwerer zu lesen als vorher...


hm? Warum das denn? Das ist Borland StandartFormatierung bis auf die Tabgröße.

mfg matze

_________________
si tacuisses, philosophus mansisses.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 19.03.05 19:26 
bzgl formatierung: folgender stil hat sich am besten bewährt
-neuen absatz zwei leerzeichen einrücken
-begin ans ende eines statements stellen, zb. so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Uses
  SysUtils;
Var
  S, D, a1, a2, op1, op2, Operation: String;
  C, B: Integer;
Begin
  ReadLn(S);
  D := S;
  B := 0;
  C := 1;
  Try
    If (Ord(D[1]) < 58And (Ord(D[1]) > 44Then begin
      While C <= Length(D) Do Begin
        B := B + 1;
        ...
      end;
    end;
  finally
  end;
end;


erzeugt kompakten, gut lesbaren code, der nicht unnötig weit nach rechts rückt, wodurch man zum scrollen gezwungen wird.

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...


Zuletzt bearbeitet von retnyg am Sa 19.03.05 19:30, insgesamt 1-mal bearbeitet
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Sa 19.03.05 19:28 
jedem das seine...

mfg matze

_________________
si tacuisses, philosophus mansisses.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Sa 19.03.05 19:31 
@matze, habe das noch begründet, siehe oben

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Sa 19.03.05 19:35 
naja vllt fürs delphi forum optimiert, aber bei mir in der IDE sieht es anders besser aus und ich kanns besser lesen.

mfg matze

_________________
si tacuisses, philosophus mansisses.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 19.03.05 19:39 
Der Code ist imho einwandfrei formatiert, man muss lediglich ein bisschen scrollen, aber das müsste man im Grunde genommen auch, wenn man nur zwei Zeichen einrücken würde... Es gibt auf jeden schlimmeres ;)

Aber jetzt bitte zurück zum Thema :mahn: ;)

_________________
JSXGraph