Autor Beitrag
michaelb31
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 31.01.06 10:24 
Hallo Leute!

Ich steh völlig auf dem schlauch wer kann mir da mal helfen:
Also ich habe ein Access Datenbank mit folgendem Inhalt :
Feld1: Name (Textfeld)
Feld2: Datum (Datumsfeld)
Feld3: Uhrzeit (datumsfeld)

Nun möchte ich diese Daten in einen Treeview anzeigen und zwar so:
zb.
30.01.2006
10:00 Herr Müller
12:00 Frau Meier

Nächstes Datum
Uhrzeit, Name
usw.
Unter Datum sollen alle Datensätze angezeigt werden die das Gleiche Datum haben

Nur wie mache ich das ?



Danke im voraus
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Di 31.01.06 12:07 
ausblenden SQL-Anweisung
1:
Select * from Tabelle order by Datum, Uhrzeit, Name					

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
  TreeView.Clear;
  Node:=Nil;
  Datum:='';
  Query.Open;
  While not Query.Eof do
  begin
    If Datum <> Query['Datum'] then
    begin
      Datum:=Query['Datum'];
      TreeView.Items.Add(Node, Datum);
    end;
    TreeView.Items.AddChild(Node, Query['Uhrzeit'] + ' ' + Query['Name']);
    Query.Next;
  end;
  Query.Close;

Ich hoffe das ist einigermaßen fehlerfrei. (hab's nicht getestet !)

Gruß Axel
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 31.01.06 17:03 
Bekomme diesen Fehler angezeigt
[Fehler] termine.pas(126): Undefinierter Bezeichner: 'Node'
und nun ? wenn ich euch nicht hätte
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 31.01.06 17:08 
Node ist eine Variable vom Typ TTreeNode

_________________
Markus Kinzler.
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 31.01.06 17:18 
Ja Klasse ! Danke
bekomme aber nun die Meldung das die Typumwandlung ungültig ist kann das mit den Datumsfeldern zusammenhängen ?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 31.01.06 17:27 
Ändere mal

ausblenden Delphi-Quelltext
1:
TreeView.Items.Add(Node, Datum);					

in
ausblenden Delphi-Quelltext
1:
Node := TreeView.Items.Add( Datum);					


Welcher Typ hat das Feld 'Datum' ?

_________________
Markus Kinzler.
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 31.01.06 17:33 
Gut das hab ich so gelöst :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm8.Button1Click(Sender: TObject);
var Node:TTreeNode;
begin
  TreeView1.Items.Clear;
  Node:=Nil;
  Datum:='';
  Query.Open;
  While not Query.Eof do
  begin
    If Datum <> Querydatum.AsString then
    begin
      Datum:=Querydatum.AsString;
      TreeView1.Items.Add(Node, Datum);
    end;
    TreeView1.Items.AddChild(Node, Queryuhrzeit.AsString  + ' ' + Queryfirma.AsString) ;
    Query.Next;
  end;
  Query.Close;

end;

nun stimmt aber die anzeige nicht richtig es werden alle daten untereinander geschrieben siehe Bild
Einloggen, um Attachments anzusehen!
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Di 31.01.06 17:51 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm8.Button1Click(Sender: TObject);
var Node:TTreeNode;
begin
  TreeView1.Items.Clear;
  Node:=Nil;
  Datum:='';
  Query.Open;
  While not Query.Eof do
  begin
    If Datum <> Querydatum.AsString then
    begin
      Datum:=Querydatum.AsString;
      Node:=TreeView1.Items.Add(Node, Datum);
    end;
    TreeView1.Items.AddChild(Node, Queryuhrzeit.AsString + ' ' + Queryfirma.AsString) ;
    Query.Next;
  end;
  Query.Close;
end;


Wie Markus bereits erwähnt hat, in Zeile 13 Node:= hinzufügen. Hab ich bei meinem ersten Beispiel falsch gemacht.

Gruß Axel
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 31.01.06 17:58 
Ihr seid echt Klasse :beer:
es klappt super !!

nur eine frage noch bekomme die Uhrzeit immer so angezeigt :"31.12.1899 13:00:00"
möchte aber nur 13:00 angezeigt bekommen wie formatiere ich das um ?
habe das hier aber ohne erfolg
ausblenden Delphi-Quelltext
1:
FormatDateTime('"hh":"mm"',datamodule1.termineUhrzeit.AsDateTime);					


bekomme aber als ergebnis nur hh:mm
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Di 31.01.06 18:03 
ausblenden Delphi-Quelltext
1:
FormatDateTime('hh:nn',datamodule1.termineUhrzeit.AsDateTime);					

Gruß Axel
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 09:13 
Wie kann man nur so blind sein :autsch:

Besten dank Ihr habt mir sehr geholfen
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 12:15 
Hab da noch eine kleine Frage ich hab das jetzt alles so gelöst:
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:
procedure TForm8.terminsuche;
var uhrzeit,jahr,monat:string;Node,Node1,Node2:TTreeNode;
begin
TreeView1.Items.Clear;
  Node:=Nil;Node1:=Nil;Node2:=Nil;
  jahr:='';
  monat:='';
  Datum:='';
  Query.Open;
  While not Query.Eof do
  begin
    if jahr <> Queryjahr.AsString then
    begin
    jahr := queryjahr.AsString;
    Node:=treeView1.Items.Add(Node, jahr);
    end;
        if monat <> querymonat.AsString then
        begin
        monat := querymonat.AsString;
        Node1:=TreeView1.Items.AddChild(Node, monat);
         end;
           If Datum <> Querydatum.AsString then
           begin
           Datum:=Querydatum.AsString;
           Node2:=TreeView1.Items.Addchild(Node1, Datum);
           end;
             uhrzeit:=FormatDateTime('hh:mm',queryuhrzeit.AsDateTime);

             TreeView1.Items.AddChild(Node2, uhrzeit + ' Uhr bei ' + Queryfirma.AsString) ;
             node2.Data:=queryid;
    Query.Next;
  end;
  Query.Close;

end;


nun meine frage dazu
ich habe jetzt alles schön in der TreeView stehen möchte aber wenn ich auf den eintrag von Uhrzeit + firma klicke diesen datensatz in der tabelle localisieren wie mache ich das ??
ich habe in meiner tabelle noch ein feld ID nur wo kann man das zuordnen und wieder auslesen ?
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Mi 01.02.06 13:43 
Dazu könntest Du die Data-Eigenschaft der TreeNodes "zweckentfremden", setzt nur einen entsprechenden Typcast voraus.

In Zeile 29 Deines Beispiels statt:
ausblenden Delphi-Quelltext
1:
TreeView1.Items.AddChild(Node2, uhrzeit + ' Uhr bei ' + Queryfirma.AsString);					

diese Zeilen verwenden:
ausblenden Delphi-Quelltext
1:
2:
NodeID:=Queryid.AsInteger;
TreeView1.Items.AddChildObject(Node2, uhrzeit + ' Uhr bei ' + Queryfirma.AsString, Pointer(NodeID));

In der Eventbehandlung zum DoppelClick sollte dann stehen:
ausblenden Delphi-Quelltext
1:
2:
3:
NodeID:=Integer(TreeView1.Selected.Data);
Query.Filter:='ID = ' + IntToStr(NodeID);
Query.Filtered:=True;

Danach sollte der entsprechende Eintrag in der Datenbank ausgewählt sein.

Gruß Axel

_________________
Man muß sparn wo mn knn !
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 15:14 
user profile iconafk hat folgendes geschrieben:
Dazu könntest Du die Data-Eigenschaft der TreeNodes "zweckentfremden", setzt nur einen entsprechenden Typcast voraus.


Ja gut und welcher ?

Moderiert von user profile iconraziel: Quote-Tag vervollständigt
michaelb31 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mi 01.02.06 16:04 
OK Danke ich hab´s
ausblenden Delphi-Quelltext
1:
var NodeID:integer;					


klappt super
afk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102

Win 2K, Win XP
Delphi 2006 Arch., Delphi 6 Ent., MS-SQL 2005 & 2000
BeitragVerfasst: Mi 01.02.06 16:08 
user profile iconmichaelb31 hat folgendes geschrieben:
Ja gut und welcher ?

Ich nehme an Du fragst nach den Typecasts ?

Die sind in meinem Beispiel doch schon enthalten !

Typecast von Integer zu Pointer:
ausblenden Delphi-Quelltext
1:
Pointer(NodeID)					

Typecast von Pointer wieder zurück zu Integer:
ausblenden Delphi-Quelltext
1:
Integer(TreeView1.Selected.Data)					


Gruß Axel

_________________
Man muß sparn wo mn knn !