Solved

To test whether treenode exists

Posted on 2003-10-22
10
578 Views
Last Modified: 2010-04-03
Hi

how do i check if a treenode with text 'uncle' in a treeview already exists?
anyone know?
cos i dont wanna add a treenode with text 'uncle' when one already exists.
0
Comment
Question by:Alpha_AI
  • 4
  • 4
10 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
Comment Utility
a sample

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function FindNodeByText(ATree : TTreeView; AText : String) : TTreeNode;
var I : integer;
begin
  result := nil;
  i := 0;
  while (i < ATree.Items.Count) and
        (ATree.Items[i].Text <> AText) do inc(i);
  if i < ATree.Items.Count then
    result := ATree.Items[i];
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if assigned(FindNodeByText(TreeView1,Edit1.text)) then
    showmessage('Node Exist')
  else
    showmessage('No Node Exist');
end;

end.

meikl ;-)
0
 

Author Comment

by:Alpha_AI
Comment Utility
Hi Kretzhmar,

you added a comment but its not here somehow.
maybe you need to add it again.
0
 

Author Comment

by:Alpha_AI
Comment Utility
now ive found it im sorry it didn't show up before
0
 

Author Comment

by:Alpha_AI
Comment Utility
hi can i ask you how to do the same for valuelisteditors
how do i test that if a word does not exist in the key area, add the word to the list.
please and i will give you some more points on top.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
a simple sample

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ValEdit;

type
  TForm1 = class(TForm)
    ValueListEditor1: TValueListEditor;
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function IsKeyInList(AList : TStrings; AKey : String) : Boolean;
begin
  result := AList.IndexOfName(AKey) > -1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsKeyInList(ValueListEditor1.Strings,edit1.Text) then
    Showmessage('Key Exists')
  else
    Showmessage('Key not Exists');
end;

end.

meikl ;-)
0
 

Author Comment

by:Alpha_AI
Comment Utility
Hay dude ive already figured it out for the valuelisteditor
it was

 for i := 0 to ValueListEditor14.Strings.Count-1 do
      begin
      value := ValueListEditor14.FindRow(noun,i);
      end;

    if value = false then
      begin
      ValueListEditor14.Values[noun] := '100';
      end;

but umm i saw a email posted just before i figured it out so i guess i owe you the extra points?

0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
>i guess i owe you the extra points?
doesn't matter, its your decission ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
don't forget the grade
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now