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 26.01.14 04:32 
Hi Delpher,

leider funktioniert die folgende Konstruktion mit einer Hilfsvariablen nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TBuchMain.qSchuelerSort(Sender: TObject);
begin                                      // IDENT_NR, NAME, VORNAME, KLASSE, GESCHLECHT,
                                           // GEBDAT, TELEFON, EMPFEHLUNG, FSPRACHE1, WPK1NAME
  sortkrit := ' KLASSE, IDENT_NR, NAME, VORNAME ';
  screen.cursor := crhourglass;
  if fileexists(label30.caption + extractfilename(TbSchueler.tablename)) then
  begin
    QSchueler.close;  QSchueler.sql.clear; 
      QSchueler.sql.text := format('select * from "%s" order by sortkrit', [TbSchueler.tablename]);
      QSchueler.prepare;
    QSchueler.open;
    datasource1.dataset := QSchueler;
  end;
  screen.Cursor := crdefault;
end;


Gibt es einen (anderen) Weg?

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1322
Erhaltene Danke: 117

Win 10
RIO, CE, Lazarus
BeitragVerfasst: So 26.01.14 07:11 
Was funktioniert denn nicht? Bzw. was für einen Fehler bekommst du denn? Auf den ersten blick würde ich sagen du ersetzt "sortkrit" im SQL nicht.
Kleiner Tipp, wenn du bei der Zuweisung mit ...SQL.Text arbeitest kannst du dir das SQL.Clear vorher schenken.

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
haentschman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 285
Erhaltene Danke: 33


DX10 Berlin Professional
BeitragVerfasst: So 26.01.14 11:13 
Moin... 8)

ok, weil heute Sonntag ist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TBuchMain.qSchuelerSort(Sender: TObject);
begin                                      // IDENT_NR, NAME, VORNAME, KLASSE, GESCHLECHT,
                                           // GEBDAT, TELEFON, EMPFEHLUNG, FSPRACHE1, WPK1NAME
  SortKrit := ' KLASSE, IDENT_NR, NAME, VORNAME ';
  Screen.Cursor := crHourGlass;
  if FileExists(Label30.Caption + ExtractFilename(TbSchueler.Tablename)) then
  begin
    QSchueler.Sql.Text := Format('select * from %s order by %s', [TbSchueler.Tablename, SortKrit]);
    QSchueler.Open;
    Datasource1.Dataset := QSchueler; //kann man auch im OI zuweisen
  end;
  Screen.Cursor := crDefault;
end;


Anmerkungen:
Kennt deine Codevervollständigung nur kleine Buchstaben?
Was passiert wenn der Tabellenname falsch geschrieben ist?
Warum die Sortierkriterien über Variable wenn die eh fix sind?

Für diesen Beitrag haben gedankt: D. Annies
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 26.01.14 11:51 
Moin Haentschman,

a) Groß- Kleinbuchstaben sind doch optional (?)

b) Kann nicht passieren

c) weil ich diese Kriterien weiterreiche, z.B. an die jeweilige Groupbox_x.caption.

Danke für deine Hilfe,
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
haentschman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 285
Erhaltene Danke: 33


DX10 Berlin Professional
BeitragVerfasst: So 26.01.14 12:00 
Zitat:
a) Groß- Kleinbuchstaben sind doch optional (?)

... ja sicher. Ich denke, daß die Lesbarkeit sehr leidet wenn nur Kleinbuchstaben benutzt werden.
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 27.01.14 10:08 
Hi Haentschman,

leider funzt der Code, den du gepostet hast, doch nicht - D6??

Schade,
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
baumina
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 305
Erhaltene Danke: 61

Win 7
Delphi 10.2 Tokyo Enterprise
BeitragVerfasst: Mo 27.01.14 10:12 
Definiere "funzt nicht".

Für diesen Beitrag haben gedankt: Martok
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: Mi 29.01.14 18:37 
Die Fehlermeldung ist: Ungültiger Feldname ... Column '' is not found.

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Mi 29.01.14 18:44 
Wie sieht denn das resultierende SQL aus?
ausblenden Delphi-Quelltext
1:
2:
QSchueler.Sql.Text := Format('select * from %s order by %s', [TbSchueler.Tablename, SortKrit]);
ShowMessage(QSchueler.Sql.Text);
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: Mi 29.01.14 20:45 
showmessage liefert:

select * from Schueler.dbf order by " Name, Vorname "

also, die Hochkommata stören wohl ...

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Mi 29.01.14 20:49 
Ich frage mich, wo die herkommen. Mit haentschmans Code sind die jedenfalls nicht zu erklären.
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: Fr 31.01.14 13:23 
Hat keiner noch eine andere Idee?

Der Tabellenname steht übrigens auch in Hochkommata, das ist aber ok.

Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Fr 31.01.14 14:34 
Ohne aktuellen Code kann man nur mutmaßen.
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: Fr 31.01.14 18:25 
Der aktuelle Code ist genau der von Haentschman.
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Fr 31.01.14 18:36 
Das kann ich beim besten Willen nicht nachvollziehen. Mein Testcode (einfach nur eine Query und einen Button aufs Formular geklatscht):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TfrmTest.ButtonTestClick(Sender: TObject);
var
  SortKrit, Tablename: string;
begin
  Tablename := 'Schueler.dbf';
  SortKrit := ' KLASSE, IDENT_NR, NAME, VORNAME ';
  Query1.Sql.Text := Format('select * from %s order by %s', [Tablename, SortKrit]);
  ShowMessage(Query1.SQL.Text);
end;

Und die Ausgabe:
Zitat:
select * from Schueler.dbf order by KLASSE, IDENT_NR, NAME, VORNAME

Für diesen Beitrag haben gedankt: D. Annies
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: Fr 31.01.14 18:37 
AHA!!
ich habe ja die %s in Hochkommata!
Jetzt mal sehen ...

_________________
ut vires desint, tamen est laudanda voluntas
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: Fr 31.01.14 18:43 
Sooooo, jetzt geht's:

[Delphi]
Query1.Sql.Text := Format('select * from "%s" order by %s', [Tablename, SortKrit]);
[/Delphi]

_________________
ut vires desint, tamen est laudanda voluntas
WasWeißDennIch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 653
Erhaltene Danke: 160



BeitragVerfasst: Fr 31.01.14 19:33 
Man sollte fremden Code auch so ausprobieren, wie er gepostet wurde ;)
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: Fr 31.01.14 20:53 
Du hast recht, das hatte ich übersehen. - Also, in dieser Sache alles gelöst!
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
jackle32
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 183
Erhaltene Danke: 7

Win7
Delphi XE5 Starter, RAD Studio XE7 Pro
BeitragVerfasst: Fr 31.01.14 21:13 
Ich frag mich grad warum so kompliziert. Ich baue meine SQL-Anfragen immer so zusammen:

ausblenden Delphi-Quelltext
1:
Query1.SQL.Text := 'SELECT * FROM ' + TbSchueler.tablename + ' ORDER BY ' + sortkrit;					


Oder kennt einer der anwesenden hier darin einen Nachteil?

Gruß,
Jack

_________________
Es gibt keine dummen Fragen, nur dumme Antworten.

Für diesen Beitrag haben gedankt: D. Annies