Autor Beitrag
propello
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 02.02.03 13:25 
hallo ihr lieben

ich habe ein kleines problem.ich hoffe ihr könnt mir helfen. was muss ich machen, damit in einem dbgrid der neuste eintrag nicht am ende drangehangen wird, sondern oben. quasi den index umdrehen. ich benutze ein tclientdataset.
CenBells
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1547

Win 7
Delphi XE5 Pro
BeitragVerfasst: So 02.02.03 14:58 
benutzt du dann ein selectSQL Statment?

Wenn ja, dann musst du dort
ausblenden Quelltext
1:
order by Datum DESC					

eintragen. Ansonsten weiß ich nicht mehr.

Gruß
Ken

Moderiert von user profile iconTino: Code-Tags hinzugefügt.
propello Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: So 02.02.03 17:19 
wenns sich irgendwie verhindern lässt,bitte ohne sql. ich benutze das tclientdataset einfach mit einem file.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 03.02.03 13:23 
Hi!

Eine nicht so elegante Methode wäre die Erstellung eines Calculated-Fields, nach dem du dann sortierst. Dafür musst du dann natürlich jedem Datensatz einen absteigenden Wert geben:

ausblenden Quelltext
1:
2:
for i:=0 to CDS.RecordCount-1 do
  CDS.FieldByName('MyCalcField').Value:=CDS.RecordCount-i;


Cu, :)
Udontknow
propello Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 03.02.03 16:02 
wozu elegant? hauptsache funktioniert.ich bedank mich mal recht
herzlich.bis denne.
propello Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Di 04.02.03 16:35 
schade, gemacht getan...allerdings erhalte ich jetzt die meldung:
Zitat:
field index out of range.

ich hab den code im oncalculatedfield-event von clientdataset1 eingetragen,und im oncreate vom formular dem indexfieldnames das calculated field zugewiesen.kann man nicht irgendwie das dbgrid beeinflussen?

Moderiert von user profile iconTino: Quote-Tags hinzugefügt.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 04.02.03 17:07 
Nicht dass ich wüsste. Hmmm, man kann natürlich dann auch ein wirkliches Datenfeld für den absteigenden Index vorsehen... Aber schön ist das nicht.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 04.02.03 17:15 
Hallo nochmal!

Die Lösung heisst wohl "persistente Indizes".

Ich habe im BDN eine Unit gefunden, die dir weiterhelfen könnte:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
(* CDSSort (c) 2002 Cary Jensen, Jensen Data Systems, Inc.
 *
 * This project includes two functions for sorting a 
 * ClientDataSet on a field at runtime using persistent
 * indexes. The first time a field is sorted, the index
 * will be an acsending index. Sorting this same field again
 * will produce a descending index. Each subsequent sort will
 * alternate between the previously generated ascending and
 * descending indexes. The SortCustomClientDataSet function
 * works with any TCustomClientDataSet, but requires runtime
 * type information (RTTI). The SortClientDataSet function
 * works only with TClientDataSets, but does not require RTTI.
 *
 *
 * This project is provided for demonstration purposes only
 *
 * No guarantees or warrantees are expressed or implied concerning
 * the applicability of techniques or code included in this example.
 * If you wish to use techniques or code included in this example,
 * it is your responsibility to test and certify any code,
 * techniques, or design adopted as a result of this project.
 *
 * For information on consulting or training services, please visit
 * http://www.JensenDataSystems.com.
 *
 * Delphi Developer Days - Information-packed Delphi (TM) seminars
 * by Cary Jensen. Visit www.DelphiDeveloperDays.com for dates and locations.
 * 
 *)
unit sortfunctions;

interface

uses
  DB, DBClient;

function SortCustomClientDataSet(DataSet: TCustomClientDataSet;
  const FieldName: String): Boolean;

function SortClientDataSet(ClientDataSet: TClientDataSet;
  const FieldName: String): Boolean;

implementation

uses TypInfo; //TypInfo needed for RTTI GetObjectProp
              //IsPublishedProp, and SetStrProp methods
              //used in SortCustomClientDataSet

function SortCustomClientDataSet(DataSet: TCustomClientDataSet;
  const FieldName: String): Boolean;
var
  i: Integer;
  IndexDefs: TIndexDefs;
  IndexName: String;
  IndexOptions: TIndexOptions;
  Field: TField;
begin
Result := False;
Field := DataSet.Fields.FindField(FieldName);
//If invalid field name, exit.
if Field = nil then Exit;
//if invalid field type, exit.
if (Field is TObjectField) or (Field is TBlobField) or
  (Field is TAggregateField) or (Field is TVariantField)
   or (Field is TBinaryField) then Exit;
//Get IndexDefs and IndexName using RTTI
if IsPublishedProp(DataSet, 'IndexDefs') then
  IndexDefs := GetObjectProp(DataSet, 'IndexDefs') as TIndexDefs
else
  Exit;
if IsPublishedProp(DataSet, 'IndexName') then
  IndexName := GetStrProp(DataSet, 'IndexName')
else
  Exit;
//Ensure IndexDefs is up-to-date
IndexDefs.Update;
//If an ascending index is already in use,
//switch to a descending index
if IndexName = FieldName + '__IdxA'
then
  begin
    IndexName := FieldName + '__IdxD';
    IndexOptions := [ixDescending];
  end
else
  begin
    IndexName := FieldName + '__IdxA';
    IndexOptions := [];
  end;
//Look for existing index
for i := 0 to Pred(IndexDefs.Count) do
begin
  if IndexDefs[i].Name = IndexName then
    begin
      Result := True;
      Break
    end;  //if
end; // for
//If existing index not found, create one
if not Result then
    begin
      DataSet.AddIndex(IndexName, FieldName, IndexOptions);
      Result := True;
    end; // if not
//Set the index
SetStrProp(DataSet, 'IndexName', IndexName);
end;

//This version does not require RTTI, but only
//works with ClientDataSets.
function SortClientDataSet(ClientDataSet: TClientDataSet;
  const FieldName: String): Boolean;
var
  i: Integer;
  NewIndexName: String;
  IndexOptions: TIndexOptions;
  Field: TField;
begin
Result := False;
Field := ClientDataSet.Fields.FindField(FieldName);
//If invalid field name, exit.
if Field = nil then Exit;
//if invalid field type, exit.
if (Field is TObjectField) or (Field is TBlobField) or
  (Field is TAggregateField) or (Field is TVariantField)
   or (Field is TBinaryField) then Exit;
//Get IndexDefs and IndexName using RTTI
//Ensure IndexDefs is up-to-date
ClientDataSet.IndexDefs.Update;
//If an ascending index is already in use,
//switch to a descending index
if ClientDataSet.IndexName = FieldName + '__IdxA'
then
  begin
    NewIndexName := FieldName + '__IdxD';
    IndexOptions := [ixDescending];
  end
else
  begin
    NewIndexName := FieldName + '__IdxA';
    IndexOptions := [];
  end;
//Look for existing index
for i := 0 to Pred(ClientDataSet.IndexDefs.Count) do
begin
  if ClientDataSet.IndexDefs[i].Name = NewIndexName then
    begin
      Result := True;
      Break
    end;  //if
end; // for
//If existing index not found, create one
if not Result then
    begin
      ClientDataSet.AddIndex(NewIndexName,
        FieldName, IndexOptions);
      Result := True;
    end; // if not
//Set the index
ClientDataSet.IndexName := NewIndexName;
end;

end.


Cu,
Udontknow


Zuletzt bearbeitet von Udontknow am Di 04.02.03 17:20, insgesamt 4-mal bearbeitet
GuGl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 35



BeitragVerfasst: Di 04.02.03 17:15 
Hi Propello,

www.delphi-forum.de/viewtopic.php?t=6305

Hier habe ich das schon mal beschrieben.
Vielleicht hilft es dir.

_________________
Gruß, GuGl
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Di 04.02.03 17:17 
Hi!

Die Eigenschaft Sort gibt es dort nicht.

Cu,
Udontknow
propello Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Di 04.02.03 19:37 
mega dank :lol: