Solved

To test whether treenode exists

Posted on 2003-10-22
10
593 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
Delphi Firemonkey Need Sample for Online Shopping Example. 2 142
Create a path if not exists 7 77
Base1 Encode/Decode 3 77
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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