Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Default Array für Klasse (https://www.delphipraxis.net/34265-default-array-fuer-klasse.html)

Pseudemys Nelsoni 20. Nov 2004 01:45


Default Array für Klasse
 
tag,

ich habe eine klasse (das unnötige hab ich weggelassen):

Delphi-Quellcode:
  PChannel = ^TChannel;
  TChannel = class
    //irgendwas drinne
  end;
  TChannels = array of TChannel;
  TChans = class(TObject)
  private
    FChannels: TChannels;
  public
    function ChannelByName(ChannelName: string): PChannel;
    property Channel[idx: integer]: PChannel read GetChannel; default;
  end;
wenn ich nun von aussen eine instanz meiner klasse habe und darauf so zugreife:

Delphi-Quellcode:
chans[0].someproc;
oder:
Delphi-Quellcode:
chans.channels[0].someproc;
dann funktioniert das auch einwandfrei.... aber wieso geht z.b das hier nicht:

Delphi-Quellcode:
for i := low(chan) to high(chan) do
oder das:
Delphi-Quellcode:
for i := low(chan.channels) to high(chan.channels) do

es sind doch arrays?

fehler ist: "Inkompatible typen"

mirage228 20. Nov 2004 08:09

Re: Default Array für Klasse
 
Zitat:

es sind doch arrays?
Deine Property Chanel[idx: integer] ist eine Array-Eigenschaft, aber kein Array selbst :!: - Sie gibt ein PChanell zurück.

Wenn Du
Delphi-Quellcode:
chans[0].someproc
schreibst, wird der Delphi Compiler
Delphi-Quellcode:
chans.GetChannel(0).someproc
daraus machen.

Und
Delphi-Quellcode:
for i := low(chan.channels) to high(chan.channels) do
funktioniert nicht, weil, wie bereits gesagt, das Property Channel kein Array ist.

Delphi-Quellcode:
for i := low(chan) to high(chan) do
Ist auch nicht richtig, da Chan die Klasse selbst ist.

Du musst also eine neue Funktion oder Eigenschaft für die Anzahl der Array Elemente schreiben. :)

mfG
mirage228

Pseudemys Nelsoni 20. Nov 2004 10:31

Re: Default Array für Klasse
 
danke dann tu ich das mal *g*


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:19 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz