AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Set-Type (also Menge) und for-in-Schleife
Thema durchsuchen
Ansicht
Themen-Optionen

Set-Type (also Menge) und for-in-Schleife

Ein Thema von s.h.a.r.k · begonnen am 28. Mai 2010 · letzter Beitrag vom 28. Mai 2010
Antwort Antwort
Seite 1 von 2  1 2      
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#1

Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 02:50
Hallo zusammen,

ich stehe gerade vor einem seltsamen sprachlichen Problem, was ich nicht ganz nachvollziehen kann. Ich hoffe ihr könnt mir hier etwas Klarheit verschaffen. Und zwar geht es um folgenden Code:

Delphi-Quellcode:
type
TRttiPropertyInfoAttributeTypes = (
  atMapping,
  atVisible,
  atNotNull
);
TRttiPropertyInfoAttributeTypesSet = Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes);

{ ... }

// folgendes lässt der Compiler zu
FAttributedProperties : array[TRttiPropertyInfoAttributeTypesSet] of TStringList;

// diese for-in-Schleife allerdings nicht
for AttributeType in TRttiPropertyInfoAttributeTypesSet do
begin

end;
Im Quelltext sind schon die wichtigen Stelle markiert. Ich verstehe nicht ganz, wieso ich diese Array-Definition machen darf, allerdings diese for-in-Schleife nicht funktioniert. Ich muss doch in beiden Fällen die gleiche Angabe machen, oder läuft das etwas anders?

Hier noch schnell die Fehlermeldung, die bei der for-in-Konstruktor erscheint:
Code:
[DCC Fehler] RttiPropertyInfo.pas(108): E2029 '(' erwartet, aber 'DO' gefunden
[DCC Fehler] RttiPropertyInfo.pas(109): E2066 Operator oder Semikolon fehlt
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#2

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 03:44
Delphi-Quellcode:
var
  AttributeType : TRttiPropertyInfoAttributeTypesSet;
begin
  for AttributeType:=Low(TRttiPropertyInfoAttributeTypes) to High(TRttiPropertyInfoAttributeTypes) do
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#3

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 03:44
Das kenne ich schon selbst Ich habe ja nicht nach der Lösung des Problems gefragt, sondern nach dem warum.
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#4

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 05:51
TRttiPropertyInfoAttributeTypeSet ist äquivalent zu TRttiPropertyInfoAttributeType, keine Menge und überflüssig.
Ersetze das durch TRttiPropertyInfoAttributeType und vrzichte auf for..in. Das geht mit Enumtypen nicht.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#5

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 05:56
Kann ich dann aber trotzdem diese Array-Definition beibehalten?
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#6

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 06:04
Code:
for AttributeType in [color=#ff003f]TRttiPropertyInfoAttributeTypesSet[/color] do
Da gehört eine Variable oder Konstante und kein Typ hin.

IN durchläuft Speicherinhalte und keine Deklarationen.

for AttributeType = Low(TRttiPropertyInfoAttributeTypesSet) to High(TRttiPropertyInfoAttributeTypesSet) do

Delphi-Quellcode:
for AttributeType = Low(TRttiPropertyInfoAttributeTypes) to High(TRttiPropertyInfoAttributeTypes) do


temp := [Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes)];
for AttributeType in temp do
PS: Es gab schonmal 'nen Thread zu sowas (letztes Jah ... find ihn nur grade nicht), in welchem es auch darum ging alle Felder eines SET zu durchlaufen.

Und da nur ein Hinweis: sowas geht nur mit vollständigen SETs

Sobald etwas wie Folgendes vorkommt, dann gibt es keine RTTI zu den Feldern des Enum/Set.
Delphi-Quellcode:
type
  a = (c=3, e=9, f);
  b = set of a;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#7

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 06:10
Zitat von s.h.a.r.k:
Kann ich dann aber trotzdem diese Array-Definition beibehalten?
Probieren geht über studieren
(Ja)
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#8

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 06:24
Zitat:
Delphi-Quellcode:
TRttiPropertyInfoAttributeTypesSet =
  Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes);
Wie schon gesagt wurde: TRttiPropertyInfoAttributeTypesSet ist kein SET, sondern ebenfalls ein ENUM!

Es ist quasi nur sowas wie eine Kopie von TRttiPropertyInfoAttributeTypes.
(ein neuer Typ, mit dem selben Wertebereich)
Code:
TRttiPropertyInfoAttributeTypesSet =
  [color=#ff0000][[/color]Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes)[color=#ff0000]][/color];

// oder

TRttiPropertyInfoAttributeTypesSet = [color=#ff0000]set of[/color]
  Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes);

// oder

TRttiPropertyInfoAttributeTypesSet = set of [color=#ff0000]TRttiPropertyInfoAttributeTypes[/color];





für SETs geht aber sowas:
Code:
for AttributeType in [color=#ff003f]TRttiPropertyInfoAttributeTypesSet[/color] do
Da gehört eine Variable oder Konstante und kein Typ hin.

IN durchläuft Speicherinhalte und keine Deklarationen.

for AttributeType = Low(TRttiPropertyInfoAttributeTypesSet) to High(TRttiPropertyInfoAttributeTypesSet) do

Delphi-Quellcode:
for AttributeType = Low(TRttiPropertyInfoAttributeTypes) to High(TRttiPropertyInfoAttributeTypes) do


temp := [Low(TRttiPropertyInfoAttributeTypes)..High(TRttiPropertyInfoAttributeTypes)];
for AttributeType in temp do
PS: Es gab schonmal 'nen Thread zu sowas (letztes Jah ... find ihn nur grade nicht), in welchem es auch darum ging alle Felder eines SET zu durchlaufen.

Und da nur ein Hinweis: sowas geht nur mit vollständigen SETs

Sobald etwas wie Folgendes vorkommt, dann gibt es keine RTTI zu den Feldern des Enum/Set.
Delphi-Quellcode:
type
  a = (c=3, e=9, f);
  b = set of a;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
10.993 Beiträge
 
Delphi 12 Athens
 
#9

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 07:14
So geht es (ich hab mal den Namen verkürzt):

Delphi-Quellcode:
type
  TMyEnum = (
    atMapping,
    atVisible,
    atNotNull
  );
  TMyEnumSet = set of TMyEnum;

const
  cAllMyEnums: TMyEnumSet
    = [Low(TMyEnum)..High(TMyEnum)];

var
  FAttributedProperties : array[TMyEnum] of TStringList;

procedure Test;
var
  AttributeType: TMyEnum;
begin
  for AttributeType in cAllMyEnums do
  begin

  end;
end;
Uwe Raabe
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.114 Beiträge
 
Delphi 12 Athens
 
#10

Re: Set-Type (also Menge) und for-in-Schleife

  Alt 28. Mai 2010, 07:49
Jupp (hatte ich ja auch schon gesagt ... Variable oder Konstante)

aber Achtung (wie ebenfalls erwähnt):
Hier wird die For-Schleife 10 Werte liefern und nicht nur 3.
Delphi-Quellcode:
type
  TMyEnum = (
    atMapping,
    atVisible,
    atNotNull = 9
  );
  TMyEnumSet = set of TMyEnum;

const
  cAllMyEnums: TMyEnumSet
    = [Low(TMyEnum)..High(TMyEnum)];

var
  FAttributedProperties : array[TMyEnum] of TStringList;

procedure Test;
var
  AttributeType: TMyEnum;
begin
  for AttributeType in cAllMyEnums do
  begin

  end;
end;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 07:12 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