Autor Beitrag
MitschL
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Do 19.05.05 09:28 
Moin,

ich habe ein Array von 'packed record'-Daten und möchte mit einem Pointer bewaffnet damit arbeiten bzw. es anlegen. Leider klappt das aber mal gar nicht. Das Ganze sieht etwa so aus.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type
  TRecips = Array of TMapiRecipDesc; //packed record aus der MAPI-Unit
  PRecips = ^TRecips;

var
  aRecips:    PRecips;
  iRecipsCnt,
  maxI:     Integer;

begin
  // maxI gesetzt
  iRecipsCnt := maxI +1;
  SetLength( aRecips^, iRecipsCnt ); // 1.Fall EAccessViolation-Error hier


OK. sag ich mir und versuche es anders, und zwar so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
// 2.Fall
//  SetLength( aRecips^, iRecipsCnt );
  getmem( aRecips, sizeof( TMapiRecipDesc ) * iRecipsCnt );

  for i := 0 to maxI do
  begin
    with aRecips^[i] do
    begin
      if i = 0 then
        ulRecipClass := MAPI_TO
      else
        ulRecipClass := MAPI_BCC; // EAccessViolation-Error, während beim 2.Element
      // anderes füllen
    end;
  end;


Die Fehler besitzen den selben Typ: EAccessViolation, also von mir verursachter Speicherzugriffs-Müll.

Ich habe mich bisher erfolgreich um solche Konstrukte schlängeln können - bis jetzt. Denn eine direkte Benutztung TRecips brachte mir auch nicht den gewünschten Erfolg.

Wenn mir einer helfen kann wäre ich hoch erfreut. (Genauere Erklärungen meiner Problematik mache ich aber auch gern)

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 19.05.05 11:04 
Du machst einen grundsätzlichen Fehler...
ausblenden Delphi-Quelltext
1:
2:
3:
type
  TRecips = Array of TMapiRecipDesc; //packed record aus der MAPI-Unit
  PRecips = ^TRecips;

TRecips ist ein dynamischer Arrays - dynamische Arrays sind aber bereits Pointer die implizit dereferenziert werden. PRecips ist also eigentlich nur ein Pointer auf einen Pointer.

Ich würde folgendes vorschlagen:
ausblenden 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:
type
  TRecips = array [0..0] of TMapiRecipDesc; //packed record aus der MAPI-Unit
  PRecips = ^TRecips;

var
  aRecips:    PRecips;
  iRecipsCnt,
  maxI:     Integer;

begin
  // maxI gesetzt
  iRecipsCnt := maxI +1;

  aRecips := GetMemory(iRecipsCnt * SizeOf(TMapiRecipDesc));
  for i := 0 to maxI - 1 do
  begin
    with aRecips^[i] do
    begin
      if i = 0 then
        ulRecipClass := MAPI_TO
      else
        ulRecipClass := MAPI_BCC;
      // anderes füllen
    end;
  end;


Abschließend kann ich dir noch empfehlen dir mein Pointer-Tutorial anzuschaun: www.manuel-poeter.de

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
MitschL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Do 19.05.05 14:10 
Erstmal ein Danke!

Ich erinnere mich dunkel daran, so ein Array-Type gesehen zu haben und warum ich es nicht nutzte: ERangeError (Bereichsprüfungsfehler), sobald ich auf das zweite Element im aRecips-Array zugreifen möchte, um es zu füllen. :?

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 19.05.05 14:22 
Achso.. du hast die Bereichsprüfung aktiviert, und dann schreit Delphi.. naja, du kannst den Typ auch anders deklarieren:
ausblenden Delphi-Quelltext
1:
2:
type
  TRecips = array [0..512] of TMapiRecipDesc; //oder eben auch noch höher


Oder, wenn dir das zu unsicher ist (wer weiß wie groß maxI wird), nur direkt mit Pointer arbeiten:
ausblenden 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:
type
  PRecips = ^TMapiRecipDesc; //packed record aus der MAPI-Unit

var
  aRecips, pTmp: PRecips;
  iRecipsCnt, maxI: Integer;
begin
  // maxI gesetzt
  iRecipsCnt := maxI +1;

  aRecips := GetMemory(iRecipsCnt * SizeOf(TMapiRecipDesc));
  pTemp = aRecips; // temporäre Kopie des Pointers
  for i := 0 to maxI - 1 do
  begin
    with pTemp^ do
    begin
      if i = 0 then
        ulRecipClass := MAPI_TO
      else
        ulRecipClass := MAPI_BCC;
      // anderes füllen
    end;
    Inc(pTemp);
  end;


Am einfachsten ist es aber IMHO, wenn du die vorherige Lösung nimmst, und die Bereichsprüfung abschaltest...

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
MitschL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Do 19.05.05 15:06 
Ich danke dir erneut!

Ich habe die Pointer-Variante verwirklicht, weil ich sie nachvollziehen kann (Ich hab in dein Tutorial reingeschnuppert. 8) )
Damit wäre das Problem gelöst. Jetzt kann ich den nächsten Thread aufmachen. :?

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)