Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Do 01.04.10 17:37 
Hallo,

aus Java kennt man ja diese Syntax für einen Setter:
ausblenden Quelltext
1:
2:
3:
void setInfos(Infos infos) {
  this.infos := infos;
}


In Delphi wollte ich dies nun übernehmen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TBuild.setInfos(infos: TInfos);
begin
  Form.infos := infos;
end;


Nur leider scheint das rechte "infos" in Zeile 3 nicht das "infos" aus Zeile 1 zu sein, sondern eher das private Attribut der Klasse "Form", also Form.infos. Werden hier andere Sichtbarkeiten verwendet als in Java? Steht hier ein privates Attribut über einem Wertparameter in der Priorisierung?

Falls ja, wie löse ich dann das Problem, ohne den Wertparameter umbenennen zu müssen?

Danke schon mal!

Ciao LHUser


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Do 01.04.2010 um 17:54
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: Do 01.04.10 17:43 
ausblenden Delphi-Quelltext
1:
property Infos Read FInfos write SetInfos;					


Und dann mit If Infos <> FInfos then ...

_________________
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.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 01.04.10 17:45 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
  TForm1 = class(TForm)
  private
    FInfos: TInfos;
  protected
    procedure SetInfos(Value: TInfos);
  published
    property Infos: TInfos read FInfos write SetInfos;
  end;

...

procedure TForm1.SetInfos(Value: TInfos);
begin
  if FInfos <> Value then
    FInfos := Value;
end;
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: Do 01.04.10 17:48 
Um das dahinter mal zu sagen: Wenn man mit Properties arbeitet (und dann mit Settern und/oder Gettern), dann nimmt man dafür in der Regel eine private Variable, deren Name ein "f" voransteht. Das ist eine ähnliche Konvention wie das "T" bei Klassennamen.

Und den Parameter im Setter nenne ich meistens auch einfach "Value", oder mit "a" vorne, also hier "aInfo".

_________________
We are, we were and will not be.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 01.04.10 23:11 
user profile iconGausi hat folgendes geschrieben Zum zitierten Posting springen:
Um das dahinter mal zu sagen: Wenn man mit Properties arbeitet (und dann mit Settern und/oder Gettern), dann nimmt man dafür in der Regel eine private Variable, deren Name ein "f" voransteht. Das ist eine ähnliche Konvention wie das "T" bei Klassennamen.

Und den Parameter im Setter nenne ich meistens auch einfach "Value", oder mit "a" vorne, also hier "aInfo".

Borland macht jeweils ein grosses F und ein grosses A. Grundsätzlich wird praktisch alles gross angefangen, ausser Enums und reservierte Wörter.