Autor Beitrag
delphiUSER5
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mi 22.02.12 19:01 
hi leute ich bins nochmal.
ich haben folgendes problem: ich habe einen record

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:
type  TFIELD1 = ARRAY OF INTEGER;

  TYPE Tvokabel = RECORD
                   s, t : STRING;
                   feld : TFIELD1;
                   ort : TListBox;
                   stelle, vocRank : INTEGER;
                 end;

//und: 
VAR voc : ARRAY OF Tvokabel;

//und einen button:

procedure TFoVoc_ask.Button6Click(Sender: TObject);
VAR j, n : INTEGER;
    b : BOOLEAN;
    hilf : Tvokabel;
begin
  n := vocanzahl-1;
  REPEAT
    j := n;
    b := FALSE;
    FOR j := 0 To n DO
    IF voc[j+1].vocRank > voc[j].vocRank THEN
    begin
      b := TRUE;
      hilf := voc[j];
      voc[j] := voc[j+1];
      voc[j+1] := hilf;
    end;
   UNTIL not b;

  LBoxSort1.Clear;
  FOR j := 0 TO n DO
  begin
    LBoxSort1.Items.Add(voc[j].s);
  end;


Problem: programm stürtzt ab und sagt: "Zugriffsverletztung bei BLABLABLA" das hilft mir nich weiter. was mache ich beim vertauschen der werte falsch? :D danke für hilfe

Moderiert von user profile iconMartok: Delphi-Tags hinzugefügt
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 22.02.12 19:56 
Als erstes schreib Deinen Code mal bitte in Delphi-Tags: <span class="inlineSyntax"><span class="codecomment">{PROTECTTAG3c07803a60eb36fafcc162121a05fcf1}</span></span>
Und dann rück ihn ordentlich ein.
Und dann sagst Du uns, in welcher Codezeile der Fehler auftritt.
Und dann gucken wir nochmal... :roll:

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
Tranx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 648
Erhaltene Danke: 85

WIN 2000, WIN XP
D5 Prof
BeitragVerfasst: Mi 22.02.12 20:22 
Soweit ich das sehe, bei derartigem Durcheinander ohne Einrückung etc sehr schwierig, liegt das wohl daran, dass Du voc nicht initialisiert hast.

Du schreibst voc als ARRAY of TVokal. Damit hat voc aber, im Gegensatz zu z.B.
ausblenden Delphi-Quelltext
1:
  voc : Array[0..100of TVokal;					


noch keine Speicherplatzzuweisung. Jeder Zugriff auf voc führt dann zu unkontrollierten Speicheroperationen irgendwohin, wo für voc nichts freigehalten wurde. Schau Dir einfach die Hilfe für Dynamische Arrays - denn das ist ein ARRAY of ... - an. Da steht alles.

_________________
Toleranz ist eine Grundvoraussetzung für das Leben.
delphiUSER5 Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mi 22.02.12 21:11 
sry leute mach ich das nächste mal :zustimm:

nein ich hab schon "voc" mit einer größe versehen: setlength(voc, vocabelanzahl); //*vocabelanzahl ist auch als integervariable deffiniert!
das is nicht das problem.

das Problem ist wahrscheinlich folgendes:
ausblenden Delphi-Quelltext
1:
2:
3:
         hilf := voc[j];
         voc[j] := voc[j+1];      
         voc[j+1] := hilf;


da bricht das programm immer ab (glaube ich zumindest, wüsste sonst nicht wo der fehler ist)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 22.02.12 21:30 
In dem Code sehe ich auch keinen Fehler - das ist ein ganz normaler Bubblesort, und ein +/-1-Fehler soltle auch nicht drin sein, wenn du das Array und die Variable vocabelanzahl so nutzt wie angegeben. :gruebel:

Setz doch mal ein paar Breakpoints und taste dich so ran an die Stelle, wo der Fehler genau auftritt. :)

_________________
We are, we were and will not be.
Gammatester
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 328
Erhaltene Danke: 101



BeitragVerfasst: Mi 22.02.12 22:34 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
und ein +/-1-Fehler soltle auch nicht drin sein, wenn du das Array und die Variable vocabelanzahl so nutzt wie angegeben.
Doch! Es ist ein +/-1 Fehler: Bei setlength(voc, vocabelanzahl) ist der höchste gültige Index vocabelanzahl-1. Also im Code entweder n := vocabelanzahl-2 setzen, oder die Schleife bis n-1 laufen lassen.

Für diesen Beitrag haben gedankt: delphiUSER5
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 23.02.12 08:50 
Ach verdammt, stimmt ja. :autsch:

_________________
We are, we were and will not be.

Für diesen Beitrag haben gedankt: delphiUSER5
delphiUSER5 Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 23.02.12 18:22 
ja danke Leute, hab heute nochmal mit en paar darüber gesprochen und die meinten das gleiche
DANKE NOCHMALS :D