Autor Beitrag
Nightfly
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Do 10.04.03 07:25 
Hi

ich filtere mit folgender ANweisung eine Tabelle
ausblenden Quelltext
1:
Table4.Filter := 'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + 'AND Ziel =' + QuotedStr(table3ziel.value) + 'AND Monat =' +QuotedStr(IntToStr(month)) + 'AND Jahr =' +QuotedStr(IntToStr(year));					


leider kommt zur Laufzeit immer "Operation nicht anwendbar"

Folgender Code funktioniert:
ausblenden Quelltext
1:
Table4.Filter := 'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + 'AND Ziel =' + QuotedStr(table3ziel.value) + 'AND Monat =' +QuotedStr(IntToStr(month));					


Es hängt also am Filtern nach dem Jahr. Das Problem was ich nicht verstehe: das Tabellenfeld Monat ist genau wie das TAbellenfeld Jahr vom Typ Short, month wie auch year sind globale Variablen vom Typ integer.

Warum geht das Filtern noch beim Monat, aber nicht beim Jahr?
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 10.04.03 08:26 
Hi
wenn Monat und Jahr numerische Felder sind, musst du beim Erzeugen des Filterstring das QuotedStr weglassen. Ausserdem solltest du vor jedem AND ein Leerzeichen einfügen
ausblenden Quelltext
1:
Table4.Filter := 'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + ' AND Ziel =' + QuotedStr(table3ziel.value) + ' AND Monat =' +IntToStr(month) + ' AND Jahr =' +IntToStr(year);					


Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Do 10.04.03 08:30 
gut, werd ich probieren, aber MONAT GEHT DOCH :(

Edit:
Also es geht mit und ohne QuotedString ...aber der beschriebene Laufzeitfehler (Operation nicht anwendbar) ghet damit leider nich weg :(
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 10.04.03 08:44 
Hast du mal mit dem Debugger geprüft, was in dem Filterstring tatsächlich drinsteht? Nicht dass da am Schluss irgendwo was abgeschnitten ist.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Do 10.04.03 10:35 
ufff.....debugger. Tut mir Leid, soweit bin ich in delphi noch nich. Aber es geht auuch nicht wenn ich bloß nach Jahr filtern will, also kann es imho nicht an der länge liegen, oder?
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Do 10.04.03 10:39 
Nein, dann scheints wohl doch eher an deinem Feld zu liegen. Auch wenn's blöd klingt: Kontrollier noch mal den FeldTyp in der Datenbank und den FeldNamen. Man hat schon Pferde vor der Apotheke kotzen sehen :puke: :wink:

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Do 10.04.03 11:38 
Hab ich nochmal gemacht. Das Feld heißt wirklich Jahr, der Typ ist S (für short) ...echt mysteriös :(
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 10:56 
So, jetzt hab ich noch elends lange rumprobiert: Nix. :(

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TRechnung.Button4Click(Sender: TObject);
begin
RSumme := 0;
Label1.Visible := True;
Label1.Caption := 'Kosten im Bereich: ';
label18.caption := Table3kostenart.Value;
Label18.Visible := True;
Label17.Visible := false;
Label19.Visible := false;
Table4.Active := false;
  Table4.Filter := 'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + ' AND Ziel =' + QuotedStr(table3ziel.value) + ' AND Monat =' +QuotedStr(IntToStr(month)) + 'AND Jahr = ' + QuotedStr(copy(DateToStr(Table3Datum.Value),7,4));
 // Table4.Filter := 'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + ' AND Ziel =' + QuotedStr(table3ziel.value) + ' AND Monat =' +QuotedStr(IntToStr(month));
Table4.filtered := true;
Table4.Active := true;
Table4.FindFirst;
RSumme := Table4Einzelpreis.Value * Table4Anzahl.Value;
while Table4.FindNext = true do RSumme := Table4Einzelpreis.Value * Table4Anzahl.Value + RSumme;
Edit4.Text := FloatToStr(RSumme);
end;


Das is meine Prozedur.

3 Fälle: Ich filtere bloß nach dem String in dem JAhr nicht vorkommt: Filtert problemlos.

Ich filtere mit dem Filter in dem Jahr vorkommt: Fehler: Operation nicht anwendbar

Und das Kuriose: Ich filtere ZUERST mit dem String mit Jahr, dann mit dem ohne (wie in dem Code daoben) ..und es klappt (bloß das halt nich nach JAhr gefiltert is, weil ja der letzte der gültige ist) ..also liegt's wohl nich am Filterausdruck, der?
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 15.04.03 11:40 
Dir wurde doch schon insoweit von LCS geholfen, daß es hieß, vor das AND solle ein Leerzeichen. Bist Du dir sicher, daß dem so ist :?:

_________________
Gruß
Hansa
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 11:45 
ne, das war's nich...hab wahrscheinlich bloß nach dem ausprobieren nich gespeichert.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 15.04.03 11:56 
Sieht Dein Quelltext so aus wie hier, oder ist er irgendwie anders? :P

_________________
Gruß
Hansa
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 11:58 
ne, das war's nich...hab wahrscheinlich bloß nach dem ausprobieren nich gespeichert.
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 11:59 
nö, warum sollte der anders sein?

Ach, ich seh grad, sind noch die // drinne, naja, das kommt noch vom rumspielen ;)
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 15.04.03 12:10 
Dann ist dem nichts mehr hinzuzufügen. Die // interessieren nicht. Dann weißt Du ja, was falsch ist. Aber noch ein Tip : Solche langen Abfrage-Strings werden nicht lesbarer, je länger sie werden. Setze lieber ein paar kleine Teilstrings zu einem langen zusammen. Offensichtlich ist Dir das falsche AND deswegen immer noch nicht aufgefallen. Das such ich aber jetzt nicht schon wieder.

_________________
Gruß
Hansa
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 12:57 
Tut mir leid, so verrat's mir doch.

ausblenden Quelltext
1:
2:
3:
4:
Table4.Filter := 
'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + 
' AND Ziel =' + QuotedStr(table3ziel.value) + 
' AND Monat =' +QuotedStr(IntToStr(month));


Der da tut's.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
Table4.Filter := 
'ArtdKosten = ' + QuotedStr(Table3artdkosten.Value) + 
' AND Ziel =' + QuotedStr(table3ziel.value) + 
' AND Monat =' +QuotedStr(IntToStr(month)) + 
' AND Jahr = ' + QuotedStr(copy(DateToStr(Table3Datum.Value),7,4)); 

und der nicht. Was ist da falsch? Hilfe, ich will's ja verstehen
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 15.04.03 13:08 
vorhin hats so ausgesehen (siehe weiter oben):

ausblenden Quelltext
1:
(table3ziel.value) + ' AND Monat =' +QuotedStr(IntToStr(month)) + 'AND Jahr = ' + QuotedStr(copy(DateToStr					


Das zweite AND ! Also hast Du in dem Statement z.B. 11AND stehen als EIN Wort. Vielleicht wird das durch das QuotedStr verhindert, dann mußt Du halt noch suchen.

_________________
Gruß
Hansa
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 13:20 
Nein, Daran liegt es nicht. Das leerzeichen ist egal, hab grad nochmal beide probiert. Wenn ich mich mit den ' oder Leerzeichen vermache kommt zur Laufzeit der Fehler "Filterausdruck fehlerhaft"

es is doch zum heulen :(
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 15.04.03 13:26 
Ich sehe keinen Fehler. Aber warum braucht man das QuotedStr überhaupt ? Ich verwende das kein einziges mal. Mach es doch einfach mal nach und nach weg und guck, was passiert. Sonst fällt mir nix mehr ein.

Noch ein allgemeiner Tip: das logische AND hat Priorität vor allen anderen Operatoren, egal ob OR,+,- usw. Ich würde mir angewöhnen, um in solchen Fällen nicht die Übersicht zu verlieren, das ganze vernünftig zu klammern. Ich habe schon Fälle gesehen, wo ein falsch gesetztes AND das ganze Programm zunichte gemacht hat. Das gilt allerdings auch für Klammern. Ich komme bestimmt locker auf 50000 Zeilen. Andere Schätzungen belaufen sich auf 250000 Zeilen. Gott bewahre mich. Wenn das nicht von vorneherein sauber strukturiert ist, na dann gute Nacht. 8)

_________________
Gruß
Hansa
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: Di 15.04.03 14:20 
Hi Nighfly
du hast doch geschrieben, dass es mit JAHR alleine auch nicht funktioniert. Probier doch mal was ganz simples:
ausblenden Quelltext
1:
Table4.Filter := 'JAHR = 2003'					

oder eben eine Jahreszahl die in der Tabelle vorkommt. Wenn das nicht funktioniert hast du ein Problem mit deinen Feldern. Wenn's funktioniert liegt der Wurm irgendwo in deiner Zuweisung.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
Nightfly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 163



BeitragVerfasst: Di 15.04.03 14:58 
Na das war doch mal ein Vorschlag. Und in der tat, das geht nicht :( Aber wenn ich nach einem Feld filtere was nich existiert, dann kommt doch "Feld nicht gefunden" ...und in meiner Tabelle steht DEFINITIV eine Spalte vom Thy short die Jahr heißt...kann das ein schlimmerer defekt sein?