Einzelnen Beitrag anzeigen

Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#9

AW: VirtualTreeView mit DIContainers kombinieren

  Alt 21. Jun 2020, 21:25
noch einmal danke für die demo es ist aber leider nicht was ich wollte.
kann sein dass ich mich falsch ausgedrückt hatte aber mir ging es darum [2] VirtualTreeViews miteinander zu verbinden
ohne dabei auf eine DB zu setzen wie (Absolute Database), ich wollte meinen eigenen password manage schreibe wie das programm (KeePass)
woh jeder record/node eine dynamische größe hat und bem speichern nur die felder speichert die tatsächlich einen eintrag enthalten um so die Datei so klein wie möglich zu halten.
deswegen hatte ich ursprünglich die Compo DIContainers gewählt weil da ne demo drin ist "DIContainers_AddressBook" die sah vielversprechend aus.
doch leider kam ich da nicht weiter sie umzuschreiben damit ich [2] VirtualTreeViews benutzen kann mit unendlich vieleen einträge auf beider seiten.

ihr könnt euch das so vorstellen wie der file explore in windows. du klickst auf einen ordner auf der linken seite und auf der rechten seite werden die datein die in dem ordner drin sind angezeiget,
oder RegEdit


so wenn ihr euch das bild im ersten pos anschaut, weiß ich wie man die virtualTreeView mit Daten füllt, das ist nicht das problem.



@Aviator
die Demo ist überkompliziert und dasselbe kannst auch einfacher/schnell/kleiner machen mit nem normalen record. es sei denn ich übersehe etwas/ en forteil.



das ist die datenstrukture die ich vorher benutzt hatte mit der Absolute Database.

Delphi-Quellcode:
(**************************** Create Encrypted File ***************************)

function TMain_Form.Create_EncryptedFile(const Filename : String; DeletePass : Boolean) : Boolean;
//var GraphicCompressionAlgorithm: TCompressionAlgorithm;
begin
  Result:= False;
  DBFilename:= FileName;


 with SecureDB do
  begin
   if Exists then
    Close;
  end;

 with Folder_Table do
  begin
   if Exists then
    Close;
  end;

 with Record_Table do
  begin
   if Exists then
    Close;
  end;


 if not ShowPassDialog('Create a new Password database') then
  begin
   SecureDB.Password:= '';
   exit;
  end;


 if (Length(SecureDB.Password) = 0) then
  Exit;

 with SecureDB do
  begin
    DatabaseName:= 'SecureDB';
    DatabaseFileName:= DBFilename;
    PageSize:= 2048;
    PageCountInExtent:= 8;
    MaxConnections:= 1;
    MultiUser:= false;
    Exclusive:= true;
   if Exists then
    begin
     Close;
     DeleteDatabase;
    end;
  end;


 (* Folder Table *)

 with Folder_Table do
  begin
    DatabaseName:= 'SecureDB';
    TableName:= 'FolderList';
   with AdvFieldDefs do
    begin
     Clear;
     Add('ID', aftAutoIncLargeint, 0, false);
     Add('ParentID', aftLargeint);
     Add('IconId', aftLargeint);
     Add('Icon', aftGraphic, 0, false, caZLIB, 4);
     Add('Title', aftWidestring, 255);
    end;
   with IndexDefs do
    begin
     Clear;
     Add('ID', 'ID', [ixPrimary]);
     Add('ByParentID', 'ParentID', []);
     Add('ByTitle', 'Title', []);
    end
  end;

 (* Record Table *)

 with Record_Table do
  begin
    DatabaseName:= 'SecureDB';
    TableName:= 'RecordList';
   with AdvFieldDefs do
    begin
     Clear;
     Add('ID', aftAutoIncLargeint, 0, false);
     Add('ParentID', aftLargeint);
     Add('FolderID', aftLargeint);
     Add('Icon', aftGraphic, 0, false, caZLIB, 4);
     Add('Title', aftWidestring, 255);
     Add('Value', aftWideMemo, 0, False, caZLIB, 4);
     Add('Comment', aftWideMemo, 0, False, caZLIB, 4);
     Add('File', aftBlob, 0, False, caZLIB, 4);
     Add('FileName', aftWideMemo, 0, False, caZLIB, 4);
     Add('IsHidden', aftBoolean);
     Add('Colored', aftBoolean);
     Add('ItemColor', aftWidestring, 10);
     Add('FontColor', aftWidestring, 10);
     Add('FontBold', aftBoolean);
    end;
   with IndexDefs do
    begin
     Clear;
     Add('ID', 'ID', [ixPrimary]);
     Add('ByParentID', 'ParentID', [ixDescending]); // RecordTree Folder
     Add('ByFolderID', 'FolderID', []); // FolderTree Folder
     Add('ByTitle', 'Title', []);
    end;
  end;




  {
  FieldByName('ItemColor').AsWideString := ColorToHex(Data.ItemColor);
  FieldByName('FontColor').AsWideString := ColorToHex(Data.FontColor);
  FieldByName('FontBold').AsBoolean    := Data.FontBold;


  }



 try
 (* create the database *)
  with SecureDB do
   begin
    if not Exists then
     CreateDatabase;
   end;

  (* create the Folder Table table *)
  with Folder_Table do
   begin
    if not Exists then
     CreateTable;
   end;

  (* create the Record Table table *)
  with Record_Table do
   begin
    if not Exists then
     CreateTable;
   end;

  if DeletePass then
   SecureDB.Password:= '';
   Result:= True;

 except
  on E: Exception do

 end;
end;
Delphi-Quellcode:
(******************************* Fill Folder-List *****************************)

function TMain_Form.FolderList_Fill(ExpandedNood : Boolean) : boolean;
 procedure FillTreeNode(Parent: PVirtualNode);
 var Node: PVirtualNode;
     Data: PNodeData;

     // test
     BlobImage : TStream;
     Image : TBitmap;
 begin
  if Assigned(Parent) then
   begin

     Data:= FolderTree.GetNodeData(Parent);
     Folder_Table.Filter:= 'ParentID = ' + IntToStr(Data^.ID);
     Folder_Table.Filtered:= true;
     Folder_Table.First;

    while not Folder_Table.Eof do
     begin
      Node:= FolderTree.AddChild(Parent);
      Data:= FolderTree.GetNodeData(Node);
      Data^.ID:= Folder_Table.FieldByName('ID').AsLargeInt;
      Data^.Title:= Folder_Table.FieldByName('Title').AsWideString;
      Data^.IconID:= Folder_Table.FieldByName('IconID').AsLargeInt;
      Folder_Table.Next;
     end;


     Node:= Parent.FirstChild;
    while Assigned(Node) do
     begin
      FillTreeNode(Node);
      FolderTree.Expanded[Node]:= true;
      Node:= Node.NextSibling;
     end;

   end;
 end;

 var Node, RootNode: PVirtualNode;
     Data: PNodeData;
begin
  Result:= False;
  FolderTree.BeginUpdate;
 try
  FolderTree.Clear;



  Node:= FolderTree.AddChild(Nil);
  Data:= FolderTree.GetNodeData(Node);
  Data^.ID:= 0;
  Data^.Title:= 'My Passwords';
  Data^.Value:= '';
  Data^.IconID:= 0;
  FillTreeNode(Node);

 (* Expand first nood 'My Passwords' *)
  RootNode:= FolderTree.GetFirst();
  FolderTree.Expanded[RootNode]:= ExpandedNood;
 finally
  FolderTree.EndUpdate;
  RecordTree_Fill(0, False);
  Result:= True;
 end;
end;
Delphi-Quellcode:
(******************************* Fill Record-List *****************************)


function TMain_Form.RecordTree_Fill(FolderID: Integer; ExpandedNood : Boolean): boolean;
var
 I : Integer;
 urlStartPos, urlStrLength: Integer;

procedure FillTreeNode(Parent : PVirtualNode);
var
 Node : PVirtualNode;
 Data : PNodeData;
 RecordData: TRecordData;
begin

 if Assigned(Parent) then
  begin
    Data:= RecordTree.GetNodeData(Parent);
    Record_Table.Filter:= 'ParentID = ' + IntToStr(Data^.ID)
    + ' ' + 'AND' + ' ' + 'FolderID = ' + IntToStr(FolderID);

    Record_Table.Filtered:= true;
    Record_Table.First;

   while not Record_Table.Eof do
    begin
     Node:= RecordTree.AddChild(Parent);
     Data:= RecordTree.GetNodeData(Node);

     Data^.ID:= Record_Table.FieldByName('ID').AsLargeInt;
     Get_Record_Data(RecordData, true);
     Data^.Title:= RecordData.Title;
    if RecordData.IsHidden then
     Data^.Value:= '[xxxxxxxx]'
    else
     Data^.Value:= RecordData.Value;

    if not RecordData.IsHidden then
     Data^.IsLink:= IsURL(RecordData.Value)
    else
     Data^.IsLink:= False;

     Data^.ItemColored:= RecordData.ItemColored;
     Data^.ItemColor:= RecordData.ItemColor;
     Data^.FontColor:= RecordData.FontColor;
     Data^.FontBold:= RecordData.FontBold;
     Data^.IconId:= I;

     RecordListImg.Add(TImageHolder.Create);
     RecordListImg.Items[I].Image:= RecordData.Icon;

     Inc(I);
     Clear_Record_Data(RecordData);
     Record_Table.Next;
    end;

    Node:= Parent.FirstChild;
   while Assigned(Node) do
    begin
      FillTreeNode(Node);
      Node:= Node.NextSibling;
    end;

  end;
end;

var
 Node, RootNode: PVirtualNode;
 Data : PNodeData;
 Image : TBitmap;
 j : Integer;
begin
  Result:= False;
  RecordTree.BeginUpdate;

  RecordTree.Clear;

 for J:= RecordListImg.Count -1 downto 0 do
  RecordListImg.Delete(j);

 if RecordListImg.Count > 0 then
  RecordListImg.DeleteRange(0, RecordListImg.Count - 1);

 try
  Image := TBitmap.Create;
  Image.PixelFormat := pf32bit;
  Image.Width:= Record_ImList16.Width;
  Image.Height:= Record_ImList16.Height;
  Record_ImList16.GetBitmap(0, Image);

  RecordListImg.Add(TImageHolder.Create);
  RecordListImg.Items[0].Image:= Image;
  Image.Free;


  Node:= RecordTree.AddChild(Nil);
  Data:= RecordTree.GetNodeData(Node);
  Data^.ID:= 0;
  Data^.Title:= 'Root';
  Data^.IconId:= 0;
  I:= 1;

  FillTreeNode(Node);


 (* Expand first nood 'My Passwords' *)
  RootNode:= RecordTree.GetFirst();
  RecordTree.Expanded[RootNode]:= True;// ExpandedNood;
 finally
  RecordTree.EndUpdate;

  Result:= True;
 end;
end;

Geändert von Wishmaster (22. Jun 2020 um 03:47 Uhr)
  Mit Zitat antworten Zitat