Solved

To test whether treenode exists

Posted on 2003-10-22
10
619 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 272
Delphi XE10 Round Image 2 224
Working with hours 3 87
How to debug For loops? 3 74
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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