В главном модуле компонента вставка узла выглядит так
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 |
//----------------------------Редактирование названия узла procedure TDBTreeView.EditNodeText; var EditNodeText:TEditNodeText; NewName:string; begin if not Assigned(Self.Selected) then exit; try Screen.Cursor:=crSQLWait; //Do_Something if not Assigned(Self.Selected) then exit; EditNodeText:=TEditNodeText.Create(Self); EditNodeText.DBTreeView:=Self; // << Ссылка на дерево if InputQuery('Введите новое название','',NewName)=true then begin if NewName='' then begin FreeAndNil(EditNodeText); exit; end else EditNodeText.UpdateNodeText(NewName); end; |
Сам модуль редактирования имени узла
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 |
unit uEditText; interface uses System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, FireDAC.UI.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys, FireDAC.VCLUI.Wait, FireDAC.Phys.MySQLDef, FireDAC.Phys.MySQL, Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet, Vcl.ComCtrls, // Для TTreeView Contnrs,vcl.dialogs, syncobjs,vcl.Forms,vcl.Controls, uSelectionOptions,uSelectedOrChecked,uDBConnectionBPL, uTreeView,uSQLQueries; type TEditNodeText=class(TComponent) private FDBTreeView:TDBTreeView; public Constructor Create(Aowner:TComponent); Destructor Destroy; property DBTreeView:TDBTreeView read FDBTreeView write FDBTreeView; procedure UpdateNodeText(Name:string); end; implementation { TEditText } constructor TEditNodeText.Create(Aowner: TComponent); begin // end; destructor TEditNodeText.Destroy; begin // end; procedure TEditNodeText.UpdateNodeText(Name: string); var qEdit:TFDQuery; DBConnectionLocal:TDBConnectionBPL; id:integer; SQLQueries:TSQLQueries; begin SQLQueries:=TSQLQueries.Create(Self); if not Assigned(FDBTreeView.Selected) then exit; id:=integer(FDBTreeView.Selected.Data^); qEdit:=TFDQuery.Create(Self); DBConnectionLocal:=TDBConnectionBPL.Create(Self); qEdit.Connection:=DBConnectionLocal.FDConnection; qEdit.SQL.Text:=SQLQueries.Edit.Text; //'UPDATE `treeview_db`.`tree` SET `Name`=:Name WHERE `id`=:id'; with qEdit.Params do begin ParamValues['Name']:=Name; ParamValues['id']:=id; end; qEdit.ExecSQL; FDBTreeView.Selected.Text:=Name; FreeAndNil(qEdit); FreeAndNil(DBConnectionLocal); FreeAndNil(SQLQueries); end; end. |