Autor Beitrag
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Sa 01.05.10 03:03 
Hey,

ich wollt mal fragen, ob es in Delphi7 eine Möglichkeit gibt die default-Eigenschaft auch einer Variable zu geben, die kein Array ist. Also so ungefähr:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  TTest = class
  private
    fInt: Integer;
  public
    property Int: Integer read fInt write fInt; default;
  end;

var 
 TestInt: Integer;

T1 := TTest.Create;
T2 := TTest.Create;
TestInt = T1 + T2;


MfG & Thx Bergmann.


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am So 02.05.2010 um 12:56

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Sa 01.05.10 10:11 
Kompilieren und ausprobieren? Hast den Quelltext doch schon getippt, noch ein Mausklick und du weißt Bescheid ;)

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 01.05.10 10:59 
Default für Array- und Non-Array-Properties machen was unterschiedliches. Mehr dazu in der Hilfe ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Sa 01.05.10 13:55 
Hey,

wenn ich das so Kompiliere, dann sagt er mir, das es die default-Eigenschaft nur für Arrays gibt. Deshalb hab ich ja gefragt, ob es so was ähnliches gibt.

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 01.05.10 14:04 
Deshalb sagte ich ja, dass default bei Non-Array was anderes bedeutet; und die Hilfe hätte Dir auch verraten was: Damit legt man den Startwert fest, für den eine Eigenschaft nicht gespeichert wird.

Spricht:

ausblenden Delphi-Quelltext
1:
property HomeopathicCode: Boolean read FHomeopathic write SetHomeopathic default true;					


Wenn im Constructor FHomeopathic auf True initialisiert wird und daher das Speichern dieses Wertes uninteressant ist (man also nur für Nicht-Homeopathischen Code diese Information benötigt).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Sa 01.05.10 17:57 
Hey,

ja das hab ich ja alles aus der Hilfe raus gelesen und auch verstanden. Die Frage war ja auch, ob ich das MyObject[x] auch für Nicht-Array-Eigenschaften hin bekomm?! Also anstatt MyOject.Int := 0; --> MyObject := 0;

MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 01.05.10 18:10 
Und welche Syntax willst du dann benutzen, um der Variablen ein TTest-Objekt zuzuweisen? Nur anhand vom Typ der rechten Seite zu unterscheiden wäre wohl etwas verwegen ;) .

_________________
>λ=
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Sa 01.05.10 18:46 
Hä? Wenn es sowas ähnliches wie ne default Eigenschaft für Nicht-Arrays gibt (die aber genau so funktioniert wie bei dem Array) dann is der Typ doch bei der Eigenschaft deklariert?! Wie ich das machen will weiß ich auch nicht, dehalb frag ich ja ob es wowas gibt ^^

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Sa 01.05.10 19:59 
Keine Angst, wenn es so etwas gäbe, hätte dich sicherlich mittlerweile jemand darauf hingewiesen :mrgreen: .

In neueren Version kannst du Records eigene implizite Konvertierungen hinzufügen, das trifft es eigentlich ziemlich genau: edn.embarcadero.com/article/34324

_________________
>λ=
dummzeuch
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 593
Erhaltene Danke: 5


Delphi 5 ent, Delphi 6 bis Delphi XE8 pro
BeitragVerfasst: Mo 03.05.10 23:12 
user profile iconBergmann89 hat folgendes geschrieben:


ich wollt mal fragen, ob es in Delphi7 eine Möglichkeit gibt die default-Eigenschaft auch einer Variable zu geben, die kein Array ist. Also so ungefähr:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
type
  TTest = class
  private
    fInt: Integer;
  public
    property Int: Integer read fInt write fInt; default;
  end;

var 
 TestInt: Integer;

T1 := TTest.Create;
T2 := TTest.Create;
TestInt = T1 + T2;



Problem dabei: Wie soll der Compiler unterscheiden, ob mit
ausblenden Delphi-Quelltext
1:
T1 := T2;					

Eine Zuweisung auf den Pointer T1 oder auf die Default Property von T1 gemeint ist?

Deshalb gibt es Default-Properties nur fuer Arrays und damit ist es eindeutig.

twm
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 05.05.10 20:33 
Hey,

das überladen der Operatoren funktioniert bei mit nich, ich hab Delphi 7 Personal. Un da steht ja das es seit Delphi 7 gehen sollte. Er will aber nich. Kann es sein, das es nur mit der Professional oder so geht?

MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Tryer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 226
Erhaltene Danke: 7



BeitragVerfasst: Mi 05.05.10 20:52 
Zitat:
features in Delphi released after the Delphi 7

Das "since" im fetten Titel verwirrt da wohl etwas.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.05.10 21:14 
Ja, die neue übersichtlichere IDE kam mit Delphi 2005, dann die stabile Version davon kombiniert mit neuen Sprachfeatures mit Delphi 2006 / Turbo Delphi.

Und danach kamen dann noch weitere Entwicklungen an der Sprache in den folgenden Versionen. Vorher, also bis einschließlich Delphi 2005, hat sich an der Sprache nicht allzuviel geändert, z.B. sowas wie Klassenmethoden wurde AFAIK aber auch schon dort eingeführt.
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 05.05.10 21:33 
Hm Mist. Gibts irgend ne FreeWare Version, die das kann? Mit Lazarus gehts schonma nich...

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.05.10 21:34 
Nicht mehr, da gab es ausschließlich Turbo Delphi. Hast du dir das nicht geholt gehabt? Bist doch lange genug dabei. ;-)
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 05.05.10 21:51 
Nee eben nich :cry: Bis jetz bin ich ja mit meinem D7 zufrieden gewesen :)

€: achnee ich habs doch xDD das war ganz weit unten in den Tiefen meiner (Un-)Ordnung :P gleich ma installen un ausprobieren^^

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^


Zuletzt bearbeitet von Bergmann89 am Mi 05.05.10 21:56, insgesamt 1-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.05.10 21:56 
Dann bleibt dir nur der umständlichere Weg über entsprechende Funktionen / Methoden. Da geht dann definitiv nix einfacheres.
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 05.05.10 22:09 
Zu früh gefreut, habs zwar geladen aber kein Key -.- Naja bleib ich halt bei dem umständlichen weg...

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^