Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.02.06 13:42 
Moin!

Wie kann ich auf das dyn. Objekt in einer with-Anweisung selbst zugreifen? Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  with TStringList.Create do try
    ShowMessage(IntToStr(Self.Count)); // self ist natürlich falsch, aber was sonst?
  finally
    Free;
  end;

Die OH sagt dazu nix. :gruebel:

cu
Narses
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mo 06.02.06 13:46 
Also auf das Attribut Count kannst du einfach mit "Count" zugreifen, ohne "Self." davor.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 06.02.06 13:50 
mit Self greift du auf dad Objekt der Methode, diw du implementierst zu, also das Formular! Du mußt das self weglassen.

_________________
Markus Kinzler.
Narses Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.02.06 14:31 
Moin!

Klar, ich hab mein Problem nicht korrekt dargestellt... :wink:

Ich möchte die Stringliste an eine andere Prozedur übergeben; was schreibe ich als Parameter in den Aufruf?

cu
Narses
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 06.02.06 14:41 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  sl: TStringList;
...
  sl := TStringList.Create;
with sl do try
    ShowMessage(IntToStr(sl.Count));  
  finally
    Free;
  end;

_________________
Markus Kinzler.
Narses Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.02.06 14:49 
Moin!

Ja, so ähnlich, aber ohne die lokale Variable, quasi die temporär-Lösung! :wink: (Ich geb ja zu, es geht mehr um Code-Eleganz, als um Sinn... :D)

cu
Narses
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Mo 06.02.06 14:58 
dann musst du die stringlist in eine eigene klasse ableiten und da drin deine funktion unterbringen, um sie im with statement aufzurufen.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 06.02.06 14:59 
Das geht so nicht. Ich frag mich aber auch, warum dasohne Variable "eleganter ist". ;-)

_________________
Markus Kinzler.
Narses Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.02.06 15:07 
Moin!

OK, danke nochmal für die Alternativen. :wink:

Um zu meiner ursprünglichen Frage zurück zu kommen: Wie kann ich auf das temp. dyn. Objekt in der with-Anweisung zugreifen?

Bisheriges Fazit: garnicht :| Korrekt?

cu
Narses
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Mo 06.02.06 15:10 
user profile iconmkinzler hat folgendes geschrieben:
Das geht so nicht.

wieso ?

user profile iconNarses hat folgendes geschrieben:
Um zu meiner ursprünglichen Frage zurück zu kommen: Wie kann ich auf das temp. dyn. Objekt in der with-Anweisung zugreifen?

nur über seine methoden und eigenschaften...
Narses Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 06.02.06 15:35 
Moin!

Ich hatte es mir schon gedacht, die OH hätte sonst auch schon darauf hingewiesen; Fazit: es geht nicht. :(

Ich mach hier mal dicht, vielleicht fällt ja doch noch jemandem was ein; bitte Nachtragen, würde mich interessieren, ob´s nicht doch einen Weg gibt. :wink:

cu
Narses