| |

VerySource

 Forgot password?
 Register
Search
View: 883|Reply: 2

A method of using TREEVIEW (I don't know much about it), it is best to have source code, please talk about it!

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-6 22:30:02
| Show all posts |Read mode
A method of using TREEVIEW (I don't know much about it), it is best to have source code, please talk about it!
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-27 17:45:01
| Show all posts
type
PMyRec = ^ TMyRec;
TMyRec = record
  FName: string;
  LName: string;
end;

procedure TForm1.Button1Click (Sender: TObject);

var
  MyRecPtr: PMyRec;
  TreeViewIndex: LongInt;
begin
  New (MyRecPtr);
  MyRecPtr ^ .FName: = Edit1.Text;
  MyRecPtr ^ .LName: = Edit2.Text;
  TreeViewIndex: = StrToInt (Edit3.Text);
  with TreeView1 do
  begin
    if Items.Count = 0 then
      Items.AddObject (nil, 'Item' + IntToStr (TreeViewIndex), MyRecPtr)
    else if (TreeViewIndex <Items.Count) and (TreeViewIndex> = 0) then

      Items.AddObject (Items [TreeViewIndex], 'Item' + IntToStr (TreeViewIndex), MyRecPtr);
  end;
end;

procedure TForm1.Button2Click (Sender: TObject);

begin
  Label1.Caption: = PMyRec (TreeView1.Selected.Data) ^. FName + '' +
                  PMyRec (TreeView1.Selected.Data) ^. LName;
end;

In fact, your machine also has!
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-10 18:15:01
| Show all posts
After finding the component, add it to the form, double-click it, right-click to add the menu and self-menu, and fill in the name of the menu to be displayed until it is as you want. Add a double-click event to the treeview:
if treeview1.Selected.Text ='Menu name 1'then
    Click the event triggered by this menu;
if treeview1.Selected.Text ='Menu name 2'then
    Click the event triggered by this menu;
E.g:
procedure TFRM_MAIN.TreeView1DblClick(Sender: TObject);
begin
  if treeview1.Selected.Text ='Add record' then
    btnadd.OnClick(sender);
  if treeview1.Selected.Text ='Delete record' then
    btndelete.OnClick(sender);
  //btnadd and btndelete are the names of buttons, and buttons have their own events.
  //I'm making it easier for the user to click the treeview event to trigger the button click event. Generally write events directly.
end;

Haha, I also did something for the first time after graduation, and really learned something.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list