tProductType表结构如下

object FDConnection1: TFDConnection
    Params.Strings = (
      'Database=ClothingTem'
      'User_Name=sa'
      'Password=123'
      'Server=(local)'
      'DriverID=MSSQL')
    Connected = True
    LoginPrompt = False
    Left = 464
    Top = 288
  end
  object FDQ: TFDQuery
    Active = True
    Connection = FDConnection1
    SQL.Strings = (
      
        'select * from tProductType  where fParentID like '#39'0%'#39' order by f' +
        'code')
    Left = 464
    Top = 240
  end
  object DataSource1: TDataSource
    DataSet = FDQ
    Left = 320
    Top = 464
  end
end

代码如下

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
  FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
  FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
  FireDAC.Phys.MSSQLDef, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS,
  FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, Vcl.StdCtrls, Vcl.Grids,
  Vcl.DBGrids, Vcl.ComCtrls, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    tv: TTreeView;
    FDConnection1: TFDConnection;
    FDQ: TFDQuery;
    DataSource1: TDataSource;
    Panel1: TPanel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);

private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
nodes:ttreenodes;
node:ttreenode ;
begin
//     TV.Items.Clear;
//     nodes:=TV.Items;
//     FDQ.Active:=true;
//     node:=nodes.add(nil,FDQ.FieldByName('fCode').Value+'_'+FDQ.FieldByName('fNAME').Value);
//     FDQ.Next;
//     while NOT FDQ.Eof  do
//     BEGIN
//          if FDQ.FieldByName('fCode').Value<>0 then
//             nodes.add(node,FDQ.FieldByName('fCode').Value+'_'+FDQ.FieldByName('fNAME').Value);  //一级三兄弟
//             FDQ.Next;
//     END;
//     nodes.GetFirstNode
end;

procedure TForm1.Button2Click(Sender: TObject);
  var
    nodes:ttreenodes;
    node:ttreenode ;
    CurItem ,CurItem1:Ttreenode ;
    nodestr:string;
    lastparent,temp:string;
    i,j:integer;
begin

TV.Items.Clear;
     nodes:=TV.Items;
     FDQ.Active:=true;
     node:=nodes.add(nil,FDQ.FieldByName('fCode').Value+'_'+FDQ.FieldByName('fNAME').Value);
     FDQ.Next;
     while NOT FDQ.Eof  do
     BEGIN
          if FDQ.FieldByName('fCode').Value<>0 then
             nodes.add(node,FDQ.FieldByName('fCode').Value+'_'+FDQ.FieldByName('fNAME').Value);  //一级三兄弟
             FDQ.Next;
     END;
     nodes.GetFirstNode;

tv.Items.BeginUpdate;
  for I := 1 to 9 do
    begin
      FDQ.SQL.Clear;
      temp:=inttostr(i);
      fdq.SQL.Text:='select * from tProductType  where fcode like '+''''+ temp+'%'  +'''';//+' order by fParentCode';
      fdq.Prepare;
      fdq.open;
      nodes:=Tv.Items;
      CurItem := TV.Items.GetFirstNode;
      if i>1 then
          for j := 1 to i-1 do
          begin
           CurItem1:=CurItem.getNextSibling;
           CurItem:= CurItem1;
          end;
      fdq.First;
      fdq.Next;
      lastparent:=fdq.FieldByName('fParentCode').AsString;
      while not fdq.Eof  do
         begin
            //如 果当前'fParentCode'与上次不一样就查找
          if  lastparent<>fdq.FieldByName('fParentCode').AsString
            then
             begin
               CurItem := TV.Items.GetFirstNode;
                while CurItem <> nil do
                   begin
                    if copy( CurItem.Text,1,pos('_',CurItem.Text)-1) =fdq.FieldByName('fParentCode').Value then
                       begin
                        CurItem.Selected:=true;
                        break;
                        end;
                       CurItem := CurItem.GetNext;
                   end;
             end ;
             begin
                 nodes.addchild(CurItem,FDQ.FieldByName('fCode').Value+'_'+FDQ.FieldByName('fNAME').Value);
                 lastparent:=fdq.FieldByName('fParentCode').AsString;
             end;
          fdq.Next;
         end;
  end; // for I := 0 to 9 do
   tv.Items.EndUpdate;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
//showmessage(tv.Items.Count.ToString );
end;

end.

运行结果如下图

动手生成 Delphi xe DBTreeview的更多相关文章

  1. 动手生成 Delphi xe DBTreeview 三级行政图树 省市县

    表结构及记录 object tarea: TFDQuery    Connection = FDConnection1    SQL.Strings = (      'select *'      ...

  2. [转载]: delphi中XLSReadWrite控件的使用(2)---delphi XE下安装

    一.下载 官方下载网址: http://www.axolot.com/components/download.htm 从这里可以下载到从Delphi5到DelphiXE全部支持的版本. 二.软件安装 ...

  3. Delphi xe 下快捷使用 FastMM 的内存泄露检测功能

    Delphi xe 集成了FastMM,调试程序是的时候可以方便地检查内存泄露了.  使用方法:在project中,添加一行: ReportMemoryLeaksOnShutdown := Debug ...

  4. Delphi XE 10 跨平台三层数据库应用教程

    Delphi XE 10 跨平台三层数据库应用教程 前言: Delphi XE 开始越来越庞大,比经典的Delphi7难用,但依然是目前所有跨平台开发工具中开发效率最高.最容易上手的,其快速设计RAD ...

  5. delphi xe 10.3 利用Git组群开发,Git服务器安装,Git 拉取,提交,推送相关设置操作

    1. Git服务器安装, 参考 https://blog.csdn.net/u012842630/article/details/97175397 Git服务器官方网站,要FQ. 2. 工具软件 gi ...

  6. delphi 2010与delphi XE破解版的冲突

    在系统中同时安装了Dephi 2010LITE版与Delphi XE lite后,总是会有一个有问题 是因为两者都是读取C:\ProgramData\Embarcadero目录下的license文件, ...

  7. delphi XE Berlin ReadProcessMemory WriteProcessMemory

    delphi  XE,Berlin [dcc32 Error] Unit9.pas(93): E2033 Types of actual and formal var parameters must ...

  8. FastReport for delphi xe 安装步骤

    FastReport for delphi xe 安装步骤 1.先关闭DELPHI:2.下载后解压到一个目录,比如:D:FR:3.打开D:FR,运行recompile.exe ->点击" ...

  9. Delphi XE的firemonkey获取当前文件所在路径的方法

    Delphi XE的firemonkey获取当前文件所在路径的方法 在之前,我们知道有三种方法: ExtractFilePath(ParamStr(0)) ExtractFilePath(Applic ...

随机推荐

  1. YouTube下载方法

    复制要下载的视频的地址 打开此链接:https://y2mate.com/youtube/9wxePpNYShQ 如下图位置粘贴视频地址,然后选择想要的分辨率点击右面的“Download”进行下载即可

  2. 用js刷剑指offer(调整数组顺序使奇数位于偶数前面)

    题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 牛客网链接 js代码 ...

  3. synchronized 和 ReentrantLock 区别是什么?(未完成)

    synchronized 和 ReentrantLock 区别是什么?(未完成)

  4. 如何python循环中删除字典元素

    //下面这行就是在循环中遍历删除字典元素的方法! for i in list(dictheme2.keys()): if dictheme2[i]<self.countFortheme: dic ...

  5. vscode插件-JavaScript(ES6) Code Snippets 缩写代表含义

    Import and export Trigger Content imp→ imports entire module import fs from 'fs'; imn→ imports entir ...

  6. FFmpeg常用命令学习笔记(六)图片与视频互转命令

    图片与视频互转命令 1.视频转图片 ffmpeg -i in.mp4 -r 1 -f image2 img-%3d.jpeg -r 1:转换图片帧率为1,也就是1秒转1张.-f image2:将媒体文 ...

  7. [HNOI2009] 有趣的数列——卡特兰数与杨表

    [HNOI 2009] 我们称一个长度为2n的数列是有趣的,当且仅当该数列满足以下三个条件: (1)它是从1到2n共2n个整数的一个排列{ai}: (2)所有的奇数项满足a1<a3<…&l ...

  8. C# 任务、线程、同步(五)

    1.数据流使用  TPL Data Flow 类库 class Program { static void Main(string[] args) { // ActionBlock(); // Sou ...

  9. C语言学习系列(六)基本语法

    一.C运算符 算术运算符(语法和java类似或基本一样略过不再描述) 关系运算符(略) 逻辑运算符(略) 位运算符 运算符 描述 实例 & 如果同时存在于两个操作数中,二进制 AND 运算符复 ...

  10. [ES2019] Represent Collision-free String Constants as Symbols in JavaScript

    ES2019 introduces the Symbol.prototype.description property. In this lesson, we'll learn why this pr ...