Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Mi 20.11.02 17:58 
Hallo,Leute !

Wie sortiere ich die Datensätze einer TTable ?

Vielleicht so :
ausblenden Quelltext
1:
Table1.AddIndex('IndexArtist','Artist', []);					


...aber dann sagt er die Fehlermeldung "Tabelle ist in Gebrauch" !

Jagg !
MrSpock
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 262



BeitragVerfasst: Mi 20.11.02 23:08 
Hallo Jagg,

grundsätzlich ist ein Index der richtige Weg. Um eine Tabelle umzustrukturieren, muss ein exklusiver Zugriff möglich sein. Kein anderer User oder Prozess darf zu diesem Zeitpunkt auf die Tabelle zugreifen. Hast du z.B. in der IDE Active auf True gesetzt, blockiert die IDE die Tabelle. Hast du in deinem Programm vor Hinzufügen des Indexes die Tabelle mit Open geöffnet, musst du sie erst wieder mit Close schließen.

Außerdem muss du nach Hinzufügen eines Indexes auch den Index noch auswählen, damit er zur Sortierung herangezogen wird. Standardmäßig ist der Primary Key gewählt, sofern er angelegt ist.

_________________
Live long and prosper
MrSpock \\//
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Do 21.11.02 11:22 
ok danke !

Jagg !
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Do 21.11.02 14:44 
Beim Starten des Programmes ist die Tabelle schon geöffnet,aber wenn ich dann diesen Code :
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
    Table1.Close;
    Table1.Exclusive := true;
    Table1.DeleteIndex ('IndexA');
    Table1.AddIndex ('IndexA','Artist',[ixExpression]);
    Table1.Active := True;
    Table1.IndexName := 'IndexA';
    DBGrid1.SetFocus;


...aufrufe sagt er die Meldung : "Tabelle in Gebrauch !"

Wieso ?

Jagg !

PS : Das Programm läuft einwandfrei,wenn ich die Tabelle beim Start öffne !
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 21.11.02 14:49 
Hi
das Hinzufügen eines Index auf diese Weise funktioniert nur wenn du die Tabelle neu erzeugst. Um zur Laufzeit einen zusätzlichen Index zu erzeugen müssest du die BDE-Funktion dbiDoRestructure aufrufen.

Borland hat folgendes geschrieben:

AddIndexDef ist nur für die Erstellung von Indexdefinitionen für Tabelle zulässig, die mit einem nachfolgenden Aufruf der Methoden CreateTable oder CreateDataSet erzeugt werden. Mit AddIndexDef können keine Indizes zu bereits vorhandenen Tabellen hinzugefügt werden.


Wenn du zur Laufzeit verschiedene Sortierfolgen benötigst, könntest du entweder die Indizes bereits beim Entwurf der Tabelle erzeugen, oder anstelle der TTable eine TQuery Komponente verwenden.

Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
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 21.11.02 14:53 
Nochmal ich
Sorry :oops: hab gerade gelesen, dass du AddIndex verwendest. Damit sollte das eigentlich funktionieren. Ich würde mal anstelle von [ixExpression], [ixCaseInsenitive] verwenden.

Gruss Lothar

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



BeitragVerfasst: Do 21.11.02 14:59 
...anstelle von [ixCaseInsensitve] sagt er auch dieselbe Fehlermeldung !
muss ich vor dem Aufruf eine neue Tabelle erstellen oder wie hast du das gemeint !

Jagg !
MrSpock
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 262



BeitragVerfasst: Do 21.11.02 18:58 
Hallo Jagg,

du musst erst den Index auswählen und darfst erst dann Active wieder auf True setzen :D

_________________
Live long and prosper
MrSpock \\//
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Fr 22.11.02 09:56 
Hi !

Also,ich habe es so gemacht wie Mr. Spock gesagt hat,erst den Index auswählen und dann Active auf True setzen,funktioniert aber trotzdem nicht !
Ich glaube,der Fehler liegt woanders,wenn ich debugge,dann bleibt er bei AddIndex stehen und sagt mir dann die Fehlermeldung !
...und was ich euch noch nicht gesagt habe,ich habe in der Datenbankoberfläche schon den Index gesetzt,also den AnfangsIndex (nennt man den auch "PrimärIndex" ?)

Kann es denn daran liegen oder noch woanders ?

Jagg !
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: Fr 22.11.02 11:24 
Hi
Ich habs mal ausprobiert (Table1 hat Exklusiven Zugriff):
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
with table1 do begin
  active  := False;
  AddIndex('IDX_TEST', 'Common_Name', [ixCaseInsensitive]);
  IndexName := 'IDX_TEST';
  Active  := True;
end;

Funktioniert wunderbar.

Gruss Lothar

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



BeitragVerfasst: Fr 22.11.02 11:54 
Code :
ausblenden Quelltext
1:
2:
3:
4:
Table1.Active := False;
Table1.AddIndex ('IndexA','Artist',[ixExpression]);
Table1.IndexName := 'IndexA';
Table1.Active := True;


...auch wenn ich Table1 zur Entwurfszeit (Exclusive := True),sagt er immer noch den Fehler !

Jagg !
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: Fr 22.11.02 12:10 
Hi
Dann ist deine Tabelle noch an irgendeiner anderen Stelle geöffnet. Kontrollier mal ob sie im DB Explorer der IDE geschlossen ist.

Gruss Lothar

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



BeitragVerfasst: Fr 22.11.02 12:14 
Also...die Tabelle ist schon geöffnet,wenn das Programm starte !
Mit deinem Code funktioniert es nur,wenn ich die Tabelle zur Laufzeit öffne,das will ich aber nicht !
Ich glaube,wir haben uns falsch verstanden :-)

Jagg !
wwerner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 185



BeitragVerfasst: Fr 22.11.02 12:22 
Hi Jagg,

ich glaube, du solltest dir mal noch ein paar Gedanken zur "robusten" Programmierung machen. Warum willst du die Tabelle nicht zur Laufzeit öffen? Das hat u. a. den Vorteil, das du viel leicher eine Fehlerbehandlung durchführen kannst, wenn z.B. die Tabelle fehlt!


:lol: Und jetzt sag nicht, bei dir fehlt die Tabelle NIE.

_________________
Gruß

Wolfgang

----------
zu hause ist es doch am schönsten


Zuletzt bearbeitet von wwerner am Fr 22.11.02 12:32, insgesamt 1-mal bearbeitet
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: Fr 22.11.02 12:29 
Dem kann ich nur zustimmen :!:

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



BeitragVerfasst: Fr 22.11.02 12:39 
Ja,Ok !

...aber kann man das denn so machen wie ich es will ?

Jagg !
wwerner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 185



BeitragVerfasst: Fr 22.11.02 12:41 
Jagg hat folgendes geschrieben:
Also...die Tabelle ist schon geöffnet,wenn das Programm starte !

Jagg hat folgendes geschrieben:

auch wenn ich Table1 zur Entwurfszeit (Exclusive := True),sagt er immer noch den Fehler !



Dann ist deine Tabelle auch in der IDE offen und du kannst nie exclusiven Zugriff auf die Tabelle erhalten

_________________
Gruß

Wolfgang

----------
zu hause ist es doch am schönsten
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Fr 22.11.02 12:48 
axo ok !