Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 09.04.06 12:43 
Hi, Delpher,

(wie) kann ich das Ergebnis der Query von oben formatiert mit 2 Nachkomastellen ausgeben?

Original-Query: select sum(preis) as summe from Buch.dbf
Ich habe es versucht mit:

ausblenden Delphi-Quelltext
1:
2:
if pos('sum', Inputstring) > 0 then
  TNumericField(QBuchstamm2.fieldbyname('summe')).displayformat := '#.00';


bzw. mit

ausblenden Delphi-Quelltext
1:
2:
if pos('sum', Inputstring) > 0 then
  TNumericField(QBuchstamm2.fields[0]).displayformat := '#.00';


Beides funzt nicht!
Wird sum nicht erkannt? - Die Schreibweise stimmt.
Wer kann mir helfen?

Danke,
Detlef A.
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: So 09.04.06 13:38 
Moin :-)
sum ist eine sog. Aggregat- oder mathematische Funktion ;-)
Mach folgendes: pack die Formatierung in das AfterOpen-Ereignis:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
...
//--Query:
Query1.SQL.Text := 'SELECT SUM(preis) as summe from Buch.dbf';
Query1.Open;
...
procedure Query1AfterOpen(DataSet: TDataSet);
begin
  (Query1.FieldByName('summe') as TNumericField).DisplayFormat := '#.00';
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 09.04.06 15:11 
Danke, Rainer,

damit probier ich es mal!

Gruß aus Lübeck,
Detlef A.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mo 10.04.06 10:58 
Hallo, Rainer,

leider funktioniert deine Idee nicht. Es wird nur eine Nachkommastelle angegeben.

Hast du (oder jemand anderer) noch eine andere Idee?

Gruß. Detlef A.
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mo 10.04.06 19:38 
user profile iconD. Annies hat folgendes geschrieben:
Hallo, Rainer,

leider funktioniert deine Idee nicht. Es wird nur eine Nachkommastelle angegeben.

Hast du (oder jemand anderer) noch eine andere Idee?

Gruß. Detlef A.

Moin Detlef :-)
Also der Code funzt schon...
Ob nun
ausblenden Quelltext
1:
TNumericField(QBuchstamm2.fieldbyname('summe')).displayformat := '#0.00';					

0der
ausblenden Quelltext
1:
(QBuchstamm2.FieldByName('summe') as TNumericField).DisplayFormat := '#0.00';					

in beiden Fällen ist die Ausgabe mit zwei Nachkommastellen...
Von daher hab ich keine andere Idee :-(
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Di 11.04.06 08:09 
Hallo, Rainer,

ich prüfe das noch mal genau ... vielleicht habe ich etwas übersehen.

Gruß, Detlef