Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

To test whether treenode exists

Posted on 2003-10-22
10
Medium Priority
?
662 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

604 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