Einzelnen Beitrag anzeigen

karl der große

Registriert seit: 4. Mär 2005
40 Beiträge
 
#3

Re: Vier VirtualStringTree auf einem Formular - ist das zuvi

  Alt 20. Mär 2005, 17:42
Mein Code sieht so aus:

Delphi-Quellcode:
function Tkalk.AddVSTObject(avst: TCustomVirtualStringTree; aNode: PVirtualNode;
   aObject: TObject): PVirtualNode;
var
   Data: PTreeData;
begin
   Result := avst.Addchild(aNode);
   data := avst.GetNodeData(Result);
   avst.ValidateNode(Result, False);
   data^.FObject := aObject;
end;

function Tkalk.AddVSTStunden(avsst: TCustomVirtualStringTree; asNode: PVirtualNode;
   aStunden: TObject): PVirtualNode;
var
   Data: PStundenData;
begin
   Result := avsst.Addchild(asNode);
   data := avsst.GetNodeData(Result);
   avsst.ValidateNode(Result, False);
   data^.FStunde := aStunden;
end;

procedure Tkalk.vstFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
   Data: PTreeData;
begin
   Data := vst.GetNodeData(Node);
   if not Assigned(Data) then
      exit;
   Data.FObject.Free;
end;


procedure TKalk.vstCompareNodes(Sender: TBaseVirtualTree; Node1,
  Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
   Data1, Data2: PTreeData;
begin
   Data1 := Sender.GetNodeData(Node1);
   Data2 := Sender.GetNodeData(Node2);
   case Column of
      0:
         Result := CompareText(TtreeDataClass(Data1.FObject).FKunde,
            TtreeDataClass(Data2.FObject).FKunde);
   end;
end;

procedure TKalk.vstHeaderClick(Sender: TVTHeader; Column: TColumnIndex;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
   if Button = mbLeft then
   begin
      with Sender, TreeView do
      begin
         if SortColumn > NoColumn then
            Columns[SortColumn].Options := Columns[SortColumn].Options + [coParentColor];
            if (SortColumn = NoColumn) or (SortColumn <> Column) then
            begin
               SortColumn := Column;
               SortDirection := sdAscending;
            end
            else
               if SortDirection = sdAscending then
                  SortDirection := sdDescending
               else
                  SortDirection := sdAscending;
            Columns[SortColumn].Color := $F7F7F7;
            SortTree(SortColumn, SortDirection, False);
         end;
   end;
end;

procedure TKalk.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var
   Data: PTreeData;
begin
   Data := Sender.GetNodeData(Node);
   if data.FObject <> nil then
   begin
      case Column of
         0:
            begin
               if Node.Parent = Sender.RootNode then
                  celltext := TTreeDataClass(Data.FObject).FKunde
               else
                  celltext := TTreeDataClass(Data.FObject).FKunde
            end;
      end;
   end;
end;

procedure TKalk.FormCreate(Sender: TObject);
var
   TreeObject: TTreeDataClass;
   Wurzel: PVirtualNode;
   Wurzel1: PVirtualNode;
   begin
      vst.BeginUpdate;
      vst.NodeDataSize := SizeOf(TTreeData);
      vst.DeleteChildren(vst.RootNode, true);
      while not db_kunden.Eof do
      begin
         TreeObject := TTreeDataClass.Create;
         TreeObject.Kunde := db_kunden.fieldByName('Suchname').AsString;
         Wurzel := AddVSTObject(VST, Nil, TreeObject);
         while not db_objektkunde.eof do
         begin
            TreeObject := TTreeDataClass.Create;
            TreeObject.Kunde := db_objektkunde.fieldbyname('NummerBeschreibung').AsString;
            Wurzel1 := addvstObject(vst, Wurzel, TreeObject);
            while not db_objektverlauf.eof do
            begin
               TreeObject := TTreeDataClass.Create;
               TreeObject.Kunde := db_objektverlauf.fieldbyName('Bezeichnung').AsString;
               addvstObject(vst, Wurzel1, TreeObject);
               db_objektverlauf.next;
            end;
            db_objektkunde.next;
         end;
         db_kunden.next;
      end;
      vst.EndUpdate;
      db_objektkunde.first;
   end;

procedure TKalk.vstGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
begin
end;

procedure TKalk.vstPaintText(Sender: TBaseVirtualTree;
  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  TextType: TVSTTextType);
begin
   with TargetCanvas do
      case Column of
         1: if Sender.FocusedNode = Node then
               Font.Color := clBlue
            else
               Font.Color := clBlack
      end;
end;

procedure TKalk.vstClick(Sender: TObject);
var
   Node: PVirtualNode;
   Data: PTreeData;
begin
   Node:=VST.FocusedNode;
   if not Assigned(Node) then
      Exit;
   Data:=VST.GetNodeData(Node);
   Showmessage(TTreeDataClass(Data.FObject).kunde);
end;

procedure TKalk.vststundenGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
   Data: PStundenData;
begin
   Data := Sender.GetNodeData(Node);
   if data.FStunde <> nil then
   begin
      case Column of
         0:
            begin
               if Node.Parent = Sender.RootNode then
                  celltext := TTreeStundenClass(Data.FStunde).FStunde
               else
                  celltext := TTreeStundenClass(Data.FStunde).FStunde
            end;
      end;
   end;
end;

procedure TKalk.vststundenFreeNode(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
var
   Data: PStundenData;
begin
   Data := vst.GetNodeData(Node);
   if not Assigned(Data) then
      exit;
   Data.FStunde.Free;
end;

procedure TKalk.vststundenCompareNodes(Sender: TBaseVirtualTree; Node1,
  Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
   Data1, Data2: PStundenData;
begin
   Data1 := Sender.GetNodeData(Node1);
   Data2 := Sender.GetNodeData(Node2);
   case Column of
      0:
         Result := CompareText(TtreeStundenClass(Data1.FStunde).FStunde,
            TtreeStundenClass(Data2.FStunde).FStunde);
   end;
end;

procedure TKalk.vststundenClick(Sender: TObject);
var
   Node: PVirtualNode;
   Data: PStundenData;
begin
   Node:=VSTstunden.FocusedNode;
   if not Assigned(Node) then
      Exit;
   Data:=VSTstunden.GetNodeData(Node);
   Showmessage(TTreeStundenClass(Data.FStunde).Stunde);

end;

procedure TKalk.Button1Click(Sender: TObject);
begin
   db_kunden.first;
   db_objektkunde.First;
end;

procedure TKalk.SeitenwahlChange(Sender: TObject);
var
   TreeObject: TTreeDataClass;
   Wurzel: PVirtualNode;
   Wurzel1: PVirtualNode;
   TreeStunden: TTreeStundenClass;
   StundenWurzel: PVirtualNode;
   StundenWurzel1: PVirtualNode;

begin
   if seitenwahl.ActivePage.Caption = 'Arbeitszeitthen
      begin
         db_mitarbeiter.first;
         db_stunden.first;
         db_stundentag.First;
         vststunden.BeginUpdate;
         vststunden.NodeDataSize := SizeOf(TTreeStundenClass);
         vststunden.DeleteChildren(vststunden.RootNode, true);
         while not db_mitarbeiter.Eof do
            begin
            TreeStunden := TTreeStundenClass.Create;
            TreeStunden.Stunde := db_mitarbeiter.fieldByName('Name').AsString;
            StundenWurzel := AddVSTStunden(vststunden, Nil, TreeStunden);
            while not db_stunden.eof do
            begin
               TreeStunden := TTreeStundenClass.Create;
               TreeStunden.Stunde := db_stundentag.fieldByName('Tag').AsString;
               StundenWurzel1 := addvstStunden(vststunden, StundenWurzel, TreeStunden);
               while not db_stunden.eof do
               begin
                  TreeStunden := TTreeStundenClass.Create;
                  TreeStunden.Stunde := db_stunden.fieldbyName('Menge').AsString;
                  addvstStunden(vststunden, StundenWurzel1, TreeStunden);
                  db_stunden.next;
               end;
               db_stundentag.next;
            end;
            db_mitarbeiter.next;
         end;
         vststunden.EndUpdate;
      end
   else if seitenwahl.ActivePage.Caption = 'Objektauswahlthen
      begin
         db_kunden.first;
         db_objektkunde.first;
         db_objektverlauf.First;
         vst.BeginUpdate;
         vst.NodeDataSize := SizeOf(TTreeData);
         vst.DeleteChildren(vst.RootNode, true);
         while not db_kunden.Eof do
         begin
            TreeObject := TTreeDataClass.Create;
            TreeObject.Kunde := db_kunden.fieldByName('Suchname').AsString;
            Wurzel := AddVSTObject(VST, Nil, TreeObject);
            while not db_objektkunde.eof do
            begin
               TreeObject := TTreeDataClass.Create;
               TreeObject.Kunde := db_objektkunde.fieldbyname('NummerBeschreibung').AsString;
               Wurzel1 := addvstObject(vst, Wurzel, TreeObject);
               while not db_objektverlauf.eof do
               begin
                  TreeObject := TTreeDataClass.Create;
                  TreeObject.Kunde := db_objektverlauf.fieldbyName('Bezeichnung').AsString;
                  addvstObject(vst, Wurzel1, TreeObject);
                  db_objektverlauf.next;
               end;
               db_objektkunde.next;
            end;
            db_kunden.next;
         end;
         vst.EndUpdate;
      end
   end;
Hab den Create in die Seitenauswahl gegeben, aber es funzt nicht
gruss karl
  Mit Zitat antworten Zitat