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: Mi 03.08.05 11:25 
Hi, Delpher,

mein Problem ist: wie kann ich so starten, dass im DBGrid1 die Tabelle Schueler immer sortiert angezeigt wird?

in IBQuery1 bis 5 ist datasource = datasource1 bis 5
in IBTable1 bis 5 ist tablename = jeweiliger Tabellenname
in IBDataset1 bis 5 ist datasource leer (kein Eintrag)
in IBTrans1 bis 5 ist database eingetragen

ausblenden volle Höhe Delphi-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:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
unit buch1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, IBCustomDataSet, IBDatabase, Grids, DBGrids,
  IBTable, Provider, DBClient, DBLocal, DBLocalI, Buttons, IBSQL, IBQuery,
  TntGrids;

type
  TForm1 = class(TForm)
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    IBDataSet1: TIBDataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    OpenDialog1: TOpenDialog;
    IBTable1: TIBTable;
    Button3: TButton;
    Label2: TLabel;
    IBTransaction2: TIBTransaction;
    IBDataSet2: TIBDataSet;
    IBTable2: TIBTable;
    DataSource2: TDataSource;
    IBTransaction3: TIBTransaction;
    IBDataSet3: TIBDataSet;
    DataSource3: TDataSource;
    IBTable3: TIBTable;
    IBTransaction4: TIBTransaction;
    IBDataSet4: TIBDataSet;
    IBTable4: TIBTable;
    DataSource4: TDataSource;
    IBTransaction5: TIBTransaction;
    IBDataSet5: TIBDataSet;
    IBTable5: TIBTable;
    DataSource5: TDataSource;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Button2: TButton;
    Button4: TButton;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Button5: TButton;
    Button6: TButton;
    Label16: TLabel;
    IBQuery1: TIBQuery;
    IBQuery2: TIBQuery;
    IBQuery3: TIBQuery;
    IBQuery4: TIBQuery;
    IBQuery5: TIBQuery;
    ListBox1: TListBox;
    TntStringGrid1: TTntStringGrid;
    Button7: TButton;
    Label17: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure lb1_fuellen(sender:Tobject);
    procedure q2sort(sender:tobject);
    procedure q5sort(sender:tobject);
    procedure Button7Click(Sender: TObject);
    procedure init(sender:Tobject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{  Prolegomena:
   in OI :   DBGrid1.Datasource -> DataSource1 - 5
             ibtable1.tablename -> := OI;  }


procedure TForm1.init(sender:Tobject);
var n, k : integer;
begin
  tntstringgrid1.cells[0,0] := 'Klasse';  tntstringgrid1.cells[1,0] := 'Name';
  tntstringgrid1.cells[2,0] := 'Vorname';
  for k := 1 to tntstringgrid1.RowCount-1 do
    for n := 0 to tntstringgrid1.ColCount-1 do
      tntstringgrid1.cells[n,k] := '';
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  ibdatabase1.Open;
  ibtransaction1.StartTransaction; ibdataset1.active := true; ibtable1.active := true;
  ibtransaction2.StartTransaction; ibdataset2.active := true; ibtable2.active := true;
  ibtransaction3.StartTransaction; ibdataset3.active := true; ibtable3.active := true;
  ibtransaction4.StartTransaction; ibdataset4.active := true; ibtable4.active := true;
  ibtransaction5.StartTransaction; ibdataset5.active := true; ibtable5.active := true;
  lb1_fuellen(self);
  q5sort(self); q2sort(self);
end;

procedure Tform1.lb1_fuellen(sender:Tobject);
begin
  listbox1.Clear;
  IBtable5.first;
  while not IBtable5.eof do
  begin
    listbox1.items.add(IBTable5.fieldbyname('KLASSE').asstring); IBTable5.Next;
  end;
end;

procedure Tform1.q2sort(sender:tobject);
begin
  with ibquery2 do
  begin
    Close; SQL.Clear; SQL.Add('select * from TBSCHUELER order by KLASSE, NAME, VORNAME'); open;
  end;
end;

procedure Tform1.q5sort(sender:tobject);
begin
  with ibquery5 do
  begin
    Close; SQL.Clear; SQL.Add('select * from AUSLEIHSATZ order by KLASSE'); open;
  end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var n : integer;
begin
  IBTable5.locate('KLASSE', listbox1.Items[listbox1.ItemIndex], []);
  init(self);

  IBquery2.locate('KLASSE', listbox1.Items[listbox1.ItemIndex], []);
  n := 1;
  while IBquery2.fieldbyname('Klasse').asstring = listbox1.Items[listbox1.ItemIndex] do
  begin
    tntstringgrid1.cells[0,n] := IBquery2.fieldbyname('Klasse').asstring;
    tntstringgrid1.cells[1,n] := IBquery2.fieldbyname('Name').asstring;
    tntstringgrid1.cells[2,n] := IBquery2.fieldbyname('Vorname').asstring;
    IBquery2.Next; inc(n);
  end;
  tntstringgrid1.RowCount := n;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ibtransaction1.Commit; ibtransaction2.Commit; ibtransaction3.Commit;
  ibtransaction4.Commit; ibtransaction5.Commit;
  ibdatabase1.close;
end;

// *******************************************

procedure TForm1.Button3Click(Sender: TObject);
begin  close  end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  datasource5.dataset := ibtable5; dbgrid1.DataSource := datasource5;
  with ibquery5 do
  begin
    Close; SQL.Clear;  SQL.Add('select count (*) from AUSLEIHSATZ'); open;
    label2.Caption := fields[0].asstring;
  end;
  label17.Caption := bitbtn1.caption;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
  datasource3.dataset := ibtable3; dbgrid1.DataSource := datasource4;
  with ibquery4 do
  begin
    Close; SQL.Clear;  SQL.Add('select count (*) from TBBUCH'); open;
    label2.Caption := fields[0].asstring;
  end;
  label17.Caption := bitbtn2.caption;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  datasource3.dataset := ibtable3; dbgrid1.DataSource := datasource3;
  with ibquery3 do
  begin
    Close; SQL.Clear;  SQL.Add('select count (*) from LEKTUEREN'); open;
    label2.Caption := fields[0].asstring;
  end;
  label17.Caption := bitbtn3.caption;
end;

procedure TForm1.BitBtn4Click(Sender: TObject);
begin
  datasource2.dataset := ibtable2; dbgrid1.DataSource := datasource2;
  with ibquery2 do
  begin
    Close; SQL.Clear;  SQL.Add('select count (*) from TBSCHUELER'); open;
    label2.Caption := fields[0].asstring;
  end;
  label17.Caption := bitbtn4.caption;
  q2sort(self);
end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
  datasource1.dataset := ibtable1; dbgrid1.DataSource := datasource1;
  with ibquery1 do
  begin
    Close; SQL.Clear;  SQL.Add('select count (*) from TBBUECHER'); open;
    label2.Caption := fields[0].asstring;
  end;
  label17.Caption := bitbtn5.caption;
  q5sort(self);
end;


end.


Wer weiß da Rat? - Vielen Dank für Hilfe,
D. Annies
Lemmy
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 792
Erhaltene Danke: 49

Windows 7 / 10; CentOS 7; LinuxMint
Delphi 7-XE10.1, VS 2015
BeitragVerfasst: Mi 03.08.05 12:01 
Hi,

acuh wenn Du mir so schöne PN schreibst muss ich Dich erst mal anpflaumen: Schmeiß IBTAble und IBQuery weg, bevor Du irgend was anderes machst! Die Kompos sind nur aus kompatibilitätsgründen da, um schnell von BDE auf Interbase umzusteigen - sonst erfüllen die keinen Zweck! Die Komponente Deiner Wahl ist TIBDataSet!

Zu Deinem Problem: Die Daten lässt Du am einfachsten den Server sortieren:

ausblenden Quelltext
1:
Select * from TBSCHUELER order by KLASSE, NAME, VORNAME					


Das hast Du ja schon so drin, nur muss jetzt das Grid die Daten von diesem IBDataSet beziehen.

Lemmy

P.S.: Ein "Select * " wird i.d.R. bei einem SQL-Server nie gemacht: lies in meinem Tuto nochmal die Stelle mit der Überschrift "Der kleine Unterschied"
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 03.08.05 14:51 
Hi, Lemmy,

danke für deine Antwort, ich lerne dein Script gerade "auswendig" :wink: .
Den "Kleinen Unterschied" habe ich unterschätzt, ich versuche jetzt, mich darum zu kümmern und es zu verstehen.

Bis dann,
Detlef Annies