Autor Beitrag
martin300
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mo 21.09.09 14:53 
Hallo,
ich möchte zb. die Prozedur
ausblenden Delphi-Quelltext
1:
procedure setx (Value : Integer);					

als Property festlegen; Rückgabewert gibt es keinen;
Wie wird diese definiert?

property x [Value: Integer] ..... wie gehts da weiter?


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 21.09.2009 um 16:35
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 21.09.09 14:57 
Also eine write-only-Property? Das müsste so gehen
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
private
   fx: Integer;
   procedure SetX(value: Integer);
public
  property X: Integer {read fx} write SetX;

//...

procedure TMyClass.SetX(value: Integer);
begin
  fx := value;
end;

_________________
We are, we were and will not be.
martin300 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mo 21.09.09 15:09 
Danke das funktioniert.
Und wie würde
ausblenden Delphi-Quelltext
1:
procedure setxy (Value1 : Integer, Value2 : Integer);					

aussehen?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 21.09.09 15:18 
Wie würde denn dann die Zuweisung an die Property einer Instanz Deiner Klasse aussehen? Wenn Du Dir diese Frage beantworteste, wirst Du erkennen, dass sowas nicht gehen kann.

Jens

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
martin300 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mo 21.09.09 16:31 
Ich hätte die Zuweisung an das Property genauso wie zu einer Methode gemacht. Nur geht das nicht.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 21.09.09 16:37 
Moin!

Klar geht das nicht, da eine Eigenschaft immer nur einen Wert annehmen kann. :zwinker: Alternativ gibt es noch Array-Properties, hier wird dir dann ein Index im Setter/Getter mitgegeben, aber jedes Eigenschaftsfeld im Array hat natürlich auch immer nur einen Wert. :idea:

Anders gesagt: versuch mal einem var Int: Integer; mehr als einen Wert zuzuweisen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
martin300 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 186
Erhaltene Danke: 2



BeitragVerfasst: Mo 21.09.09 17:55 
Ich habe mir von den Propertys mehr erwartet, als nur einen Zugriff auf Variablen. Naja.
Eine Frage habe ich noch zu den Array Propertys. Als Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  TSimpleStringList = class
  private
    FList: array of string;
  protected
    function Get(Index: Integer): string;
    procedure Put(Index: Integer; const S: string);
  public
    property Strings[Index: Integer]: string read Get write Put; default;
  end;


Was passiert beim Anruf von
ausblenden Delphi-Quelltext
1:
strings[0] := 'text';					

bzw. wie wird es zu
ausblenden Delphi-Quelltext
1:
put(0,'text');					
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 21.09.09 19:06 
user profile iconmartin300 hat folgendes geschrieben Zum zitierten Posting springen:
Ich habe mir von den Propertys mehr erwartet, als nur einen Zugriff auf Variablen.


Ein Property ist lediglich eine Kurzform fuer den Aufruf einer Setter/Getter-Methode oder fuer den Zugriff auf eine Variable. Was eine Setter/Getter-Methode dann macht, kann beliebig komplex sein. Das Setzen einer Variablen ist nur der einfachste Fall.

user profile iconmartin300 hat folgendes geschrieben Zum zitierten Posting springen:

Eine Frage habe ich noch zu den Array Propertys. Als Beispiel:
...
Was passiert beim Anruf von
ausblenden Delphi-Quelltext
1:
strings[0] := 'text';					

bzw. wie wird es zu
ausblenden Delphi-Quelltext
1:
put(0,'text');					


Was soll da passieren? Der Compiler erkennt eine Property-Zuweisung und generiert den Aufrufcode fuer die Setter-Methode.

twm