Autor Beitrag
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Di 08.11.05 11:19 
Hallo, ich habe ein Problem eher theoretische Natur und zwar will ich in etwa sowas machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var tmpAuto:TAuto;

DB Zugriff
for i:= 0 to Db.count-1
begin
  tmpAuto := TAuto.Create(Db.FieldbyName('Räder').Asinteger,...);
  Liste.Add(tmpAuto);
end;

Da die Konstanten, die ich für das Statement des DB Zugriffs brauche semantisch sehr gut zu der tAuto Klasse passen, wäre es ja sinnvoll, diese darin zu integrieren.
Während des DB Zugriffs ist aber noch kein Objekt der Klasse TAuto erstellt und ich könnte somit nicht auf die Konstanten zugreifen.

Ich suche soetwas wie KlassenMethoden aber diese können ja nicht auf Elemente der Objektklasse zugreifen.
Gibt es da eine Lösung die einigermaßen "wohlgeformt" ist?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Di 08.11.05 11:29 
1. Bau eine Klassenmethode, die eine Konstante enthält und diese zurückliefert. Finde ich nicht sonderlich schön.

2. Definiere die Konstante in der Klassenunit von TAuto im Interface-Teil. Ist zwar dann Datentechnisch nicht an TAuto gebunden, aber zumindest mal an der richtigen Stelle im Code.

_________________
Bravery calls my name in the sound of the wind in the night...
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Di 08.11.05 13:26 
An 1. dachte ich auch aber naja das ist schon n bissel blöde.

2. find ich auch nicht sooo schön.

Ist wie gesagt nur ein theoretisches Problem, falls ich mal den Code umstellen will.
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 08.11.05 14:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
TAuto = class
    class function Name: String;
end;

class function Name: String;
begin
  Result := 'Räder';
end;

und der Aufruf mit
ausblenden Delphi-Quelltext
1:
TAuto.Name;					

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Di 08.11.05 15:47 
Naja gut das wäre natürlich eine Möglichkeit :-)
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Di 08.11.05 16:09 
Kannst das ja auch so bauen, dass alle Abfragen, die mit dem TAuto zu tun haben auch von diesem ausgeführt werden, also komplette Datenkapselung..

_________________
Bravery calls my name in the sound of the wind in the night...
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mi 09.11.05 08:52 
Ja aber dann würdest du wenn du 100 Autos aus der DB kreirst auch 100 Abfragen haben obwohl du mit einer Abfrage alle haben könntest ;)
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 09.11.05 09:03 
Das is richtig. Kommt halt immer auf den konkreten Anwendungsfall an, was sinnvoll ist.

_________________
Bravery calls my name in the sound of the wind in the night...