Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- AnsiString Str[12];
- int StrCount;
- int ii;
- AnsiString ss1;
- TTreeNode *Node[6],*NNode;
- int lastw=3,NodeID=0;
- Str[0]="101";
- Str[1]="101001";
- Str[2]="101001001";
- Str[3]="101001002";
- Str[4]="102";
- Str[5]="102001";
- Str[6]="102002";
- Str[7]="103";
- Str[8]="103001";
- Str[9]="103001001";
- Str[10]="103001001001";
- StrCount=11;
- Node[0]=TreeView1->Items->GetFirstNode();
- TreeView1->Items->Clear();
- for(ii=0;ii<StrCount;ii++)
- {
- ss1=Str[ii];
- if(ss1.Length()==lastw)
- {
- Node[NodeID]=TreeView1->Items->Add(Node[NodeID],ss1);
- NNode=Node[NodeID];
- }
- else if(ss1.Length()>lastw)
- {
- Node[NodeID+1]=TreeView1->Items->AddChild(Node[NodeID],ss1);
- NNode=Node[NodeID+1];
- lastw=ss1.Length();
- NodeID++;
- }
- else
- {
- lastw=ss1.Length();
- NodeID=lastw/3-1;
- Node[NodeID]=TreeView1->Items->Add(Node[NodeID],ss1);
- NNode=Node[NodeID];
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- AnsiString Str[12];
- int StrCount;
- int ii;
- AnsiString ss1;
- TTreeNode *Node[6],*NNode;
- int lastw=3,NodeID=0;
- Str[0]="101";
- Str[1]="101001";
- Str[2]="101001001";
- Str[3]="101001002";
- Str[4]="102";
- Str[5]="102001";
- Str[6]="102002";
- Str[7]="103";
- Str[8]="103001";
- Str[9]="103001001";
- Str[10]="103001001001";
- StrCount=11;
- Node[0]=TreeView1->Items->GetFirstNode();
- TreeView1->Items->Clear();
- for(ii=0;ii<StrCount;ii++)
- {
- ss1=Str[ii];
- if(ss1.Length()==lastw)
- {
- Node[NodeID]=TreeView1->Items->Add(Node[NodeID],ss1);
- NNode=Node[NodeID];
- NNode->ImageIndex=0;NNode->SelectedIndex=1;
- }
- else if(ss1.Length()>lastw)
- {
- Node[NodeID+1]=TreeView1->Items->AddChild(Node[NodeID],ss1);
- NNode=Node[NodeID+1];
- NNode->ImageIndex=0;NNode->SelectedIndex=1;
- lastw=ss1.Length();
- NodeID++;
- }
- else
- {
- lastw=ss1.Length();
- NodeID=lastw/3-1;
- Node[NodeID]=TreeView1->Items->Add(Node[NodeID],ss1);
- NNode=Node[NodeID];
- NNode->ImageIndex=0;NNode->SelectedIndex=1;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- TTreeNode *Node;
- AnsiString ass;
- int idx;
- Node=TreeView1->Selected;
- if(Node!=NULL)
- {
- idx=TreeView1->Selected->AbsoluteIndex;
- if(TreeView1->Items->Item[idx]->HasChildren==False)
- {
- ass=TreeView1->Items->Item[idx]->Text;
- ShowMessage(ass);
- }
- else
- ShowMessage("has Child");
- }
- }
- //---------------------------------------------------------------------------