Solved

To test whether treenode exists

Posted on 2003-10-22
10
586 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
ID: 9597307
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
ID: 9597341
Hi Kretzhmar,

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

Author Comment

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

Author Comment

by:Alpha_AI
ID: 9597667
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9597738
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
ID: 9597744
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
ID: 9597766
>i guess i owe you the extra points?
doesn't matter, its your decission ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9604881
don't forget the grade
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
Delphi Mdi application Child forms get behind control 7 157
Magic Software info 18 125
Dev Express grid collapse 2 39
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

15 Experts available now in Live!

Get 1:1 Help Now