Autor Beitrag
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 21.01.06 21:41 
Hallo Kollegen,

ich seh zur Zeit den Wald vor lauter Bäumen nicht mehr, kann mir kurz einer zur Hand gehen.

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:
...
//in Klasse als Private deklariert.
      DLHKostKat: tList;
....

type
  pRecHKostKat = ^tRecHKostKat;
  tRecHKostKat = record
   hKostkat, atext: string;
  end;

 procedure AddHKostKat;
 var
  q: tquery;
  s: string;
  c: char;
  kk: pRecHKostKat;
 begin
  q := tquery.Create(NIL);
  q.DatabaseName := 'db';
  s := 'select hkostkat, atext from hkostkat';
  q.Close; q.SQL.Clear;
  q.SQL.Add(s);
  c := #0;
  q.open;
  if q.recordcount > 0 then
  begin
   q.first;
   while not q.eof do
   begin
    kk := new(pRecHKostKat);
    dlHKostKat.Add(kk);
    move(c, kk^, sizeof(pRecHKostKat));
    kk^.hKostkat := q.Fields[0].AsString;
    kk^.atext    := q.Fields[1].AsString;
    q.next;
   end;
  end;
  q.close;
  q.Free;
 end;


An der Stelle kommt es zu einer Exception EAccessViolation. Die Liste ist aber vorgängig initialisiert. Hat jemand eine Idee, an was es liegen könnt?

<TIA>

MfG.

Moderiert von user profile iconUGrohne: Delphi-Tags hinzugefügt.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 22.01.06 02:02 
Ist sicher, dass q.Fields[0] auch existiert?
Vllcht ist der Index 0 zu hoch, so mal als Tipp ins leere

_________________
Programmers never die, they just GOSUB without RETURN
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 22.01.06 09:32 
hallo alias5000,

danke für den tip, aber das feld q.fields[0].asstring existiert, und verweisst in diesem fall auf hkostkat->hkostkat.

das problem ist von meiner seite in der zwischenzeit ein wenig eingegrenzt. es liegt am move befehl.

an dieser stelle kommt er nur auf das speicherproblem, weil es gerade der erste befehl nach dem move ist, der auf den selben spreicherbereich zeigt.

grüsse


ps: wie kann man hier die delphi-tags einfügen?
alex517
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 60


D7Ent, FB, FIBPlus
BeitragVerfasst: So 22.01.06 10:12 
Hallo Grenzgaenger,

ich bin mir nicht ganz sicher was du mit move(c, kk^, sizeof(pRecHKostKat)) erreichen willst.
Ich tippe mal auf Inhalt von kk^ mit 0 initialisieren.

laut Delphi-Hilfe:
Move kopiert Count Bytes vom Speicherblock Source in den Block Dest.
Bei der Operation wird keine Bereichsprüfung durchgeführt.

d.h mit deiner Methode werden sizeof(pRecHKostKat) Bytes beginnend mit c
nach kk^ kopiert. Das Problem dabei ist, dass c nur 1 Char lang ist.
Den Rest bildet alles was nach c im Speicher steht, was auch immer ist das ist.

Du solltes besser folgendes verwenden:
ausblenden Delphi-Quelltext
1:
Fillchar(kk^, sizeof(pRecHKostKat), 0);					

alex
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 22.01.06 10:19 
Die Delphi Tags kannst du entweder im Editor unter "Bereiche" einfügen.
Dort musst du in der ersten Combobox Delphi auswählen und dann auf das "+" drücken. Um den Tag zu schließen tust du dasselbe.

Oder du schreibsts ihn manuell rein, ist ganz einfach.
Dazu benutzt du einfach: "[Delphi ]" und [/Dellphi ]
Die Leerzeichen nach Delphi musst du natürlich weglassen. Ich mach sie hier rein, damit du den Text auch noch siehst und das nicht in echte Tags gesetzt wird.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 22.01.06 10:45 
danke, alex517,

das mit dem initialisieren war richtig geraden. kannte bis anhin den befehl "fillchar" noch nicht. sollt vielleicht öfters mal die doku lesen ;-) .

mit dem fillchar, funktioniert die ganze geschichte wieder. tja, war zum ersten mal, dass es da mit dem "move" zu einem problem kam. aber einmal ist ja bekanntlich immer das erste mal.

dank und gruss
wolf

ps: danke alias500, für den tip mit den delphi tags.