Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 22.06.08 09:09 
Hallo,

habe ein Problem bei folgender Deklaration:

ausblenden Delphi-Quelltext
1:
2:
3:
type TFieldImage = class(TImage)
  fieldType: TFieldType;
end;


Ich bekomme immer die Fehlermeldung vom Compiler
"[DCC Fehler] Unit1.pas(12): E2217 Published-Feld 'fieldType' ist weder vom Typ class noch interface"

Kann mir jemand sagen, was ich dagegen tun kann?

_________________
1405006117752879898543142606244511569936384000000000.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 22.06.08 09:23 
Kann mir das eigentlich nur so erklären, dass du einen vordefinierten Begriff verwendest. Ansonsten ist ja nichts besonderes an deiner Deklaration.

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
SvenAbeln
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 334
Erhaltene Danke: 3



BeitragVerfasst: So 22.06.08 12:04 
In der Delphi Hilfe zu der Fehlermeldung steht doch die Lösung:

entweder:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  type TFieldImage = class(TImage)
  public
    fieldType: TFieldType;
  end;


oder wenn es wirklich Published sein soll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  type TFieldImage = class(TImage)
  private
    FFieldType: TFieldType;
  published
    Property FieledType: TFieldType read FFieldType write FFieldType;
  end;
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 22.06.08 12:40 
user profile iconWolle92 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
type TFieldImage = class(TImage)
  fieldType: TFieldType;
end;

Du solltest bei Klassen immer eine Sichtbarkeit für jedes Symbol definieren. Wahrscheinlich übernimmt Delphi sonst diese Einstellung von der abgeleiteten Klasse, und die ist eben published.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 22.06.08 12:55 
Die Sichtbarkeit für jedes Element zu definieren ist überflüssig. Es ist sehr eindeutig geregelt, welches Element welche Sichtbarkeit erhält:
Delphi Referenz hat folgendes geschrieben:
Ein Element ohne Attribut erhält automatisch die Sichtbarkeit des vorhergehenden Elements in der Deklaration. Die Elemente am Anfang einer Klassendeklaration ohne explizite Sichtbarkeitsangabe werden standardmäßig als
published deklariert, wenn die Klasse im Status {$M+} compiliert oder von einer mit {$M+} compilierten Klasse
abgeleitet wurde. Andernfalls erhalten sie das Attribut public.

IMHO würde es sogar der Übersichtlichkeit schaden, wenn man für jedes Element das Attribut dabei hat.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 22.06.08 13:08 
user profile iconChristian S. hat folgendes geschrieben:
IMHO würde es sogar der Übersichtlichkeit schaden, wenn man für jedes Element das Attribut dabei hat.

Ich schreibe ja auch nicht vor jedes Symbol dieses Attribut davor, sondern eher in der Art:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type TMyClass = class
private
  fField: Integer;
  fDummy: String;
  fFoo: array of Boolean;

  procedure SetDummy(const Value: String);
public
  property Field: Integer read fField write fField;
published
  procedure DoSomething;

  property Dummy: String read fDummy write SetDummy;
end;
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 22.06.08 13:16 
Ach so, dann hatte ich Dich falsch verstanden. So ist das ja die in der Referenz auch empfohlene Vorgehensweise :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 22.06.08 13:43 
user profile iconChristian S. hat folgendes geschrieben:
Ach so, dann hatte ich Dich falsch verstanden. So ist das ja die in der Referenz auch empfohlene Vorgehensweise :-)

Puh, ich dachte schon, ich hätte es die ganze Zeit unsauber gemacht :D