AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Delphi Zugriffsverletzung bei Zeiger auf statisches Array
Thema durchsuchen
Ansicht
Themen-Optionen

Zugriffsverletzung bei Zeiger auf statisches Array

Ein Thema von Codehunter · begonnen am 26. Aug 2019 · letzter Beitrag vom 26. Aug 2019
Antwort Antwort
Benutzerbild von gubbe
gubbe

Registriert seit: 8. Okt 2005
Ort: Schleswig-Holstein
150 Beiträge
 
Delphi 11 Alexandria
 
#1

AW: Zugriffsverletzung bei Zeiger auf statisches Array

  Alt 26. Aug 2019, 11:42
Warum nicht klassisch objektorientiert, ganz ohne hässliche Pointer?

Code:

unit Unit1;

interface

type
  TMyRecord = record
    A: Integer;
    B: Integer;
    C: Byte;
  end;

  TMyClass = class
  private
  protected
    function GetRecord(const AIndex: Integer): TMyRecord; virtual; abstract;
  public
    property Records[const AIndex: Integer]: TMyRecord read GetRecord; default;
  end;

  TMyClassA = class(TMyClass)
  strict private const
    RECS: array[0..1] of TMyRecord = (
      (A: 1; B: 2; C: 3),
      (A: 4; B: 5; C: 6)
    );
  protected
    function GetRecord(const AIndex: Integer): TMyRecord; override;
  public
  end;

  TMyClassB = class(TMyClass)
  strict private const
    RECS: array[0..2] of TMyRecord = (
      (A: 1; B: 2; C: 3),
      (A: 4; B: 5; C: 6),
      (A: 7; B: 8; C: 9)
    );
  protected
    function GetRecord(const AIndex: Integer): TMyRecord; override;
  end;

implementation

function TMyClassA.GetRecord(const AIndex: Integer): TMyRecord;
begin
  result := Recs[AIndex];
end;

function TMyClassB.GetRecord(const AIndex: Integer): TMyRecord;
begin
  result := Recs[AIndex];
end;

end.
Und so kannst Du auch die Übergabeparameter noch prüfen.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:18 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz