Solved

DevExpress - Deleting a list of subitems..

Posted on 2011-03-24
9
955 Views
Last Modified: 2012-05-11
ListSo I have that list of subitems on a form and I need a code to delete the list.
I was reaching at something more or less like:

 for i := dxBarSubItem1.Count - 1 downto 0 do
  begin
    if dxBarsubItem1.Items[i] is TdxBarLargeButton then
    TdxBarLargeButton(dxBarSubItem1.Controls[i]).Free;
  end;

Open in new window


Problem is that there is no "Controls"..
How can I do this?

Also got these errors on line 1 and 3 of the code above:
Undeclared identifier: 'Count'
'THEN' expected but identifier 'Items' found

Thanks.
0
Comment
Question by:John86a
[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
  • 5
  • 4
9 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35209491


do this
for i := dxBarSubItem1.Count - 1 downto 0 do
  begin
    if dxBarsubItem1.Items[i] is TdxBarLargeButton then
    begin
      //check if there is a delete method, this would be better
      dxBarsubItem1.Items.Delete(I);
      //or
      TObject(dxBarsubItem1.Items[i]).Free; //but this does not remove the nil item from the list

    end;
  end;

Open in new window

0
 

Author Comment

by:John86a
ID: 35209526
Sorry, I edited the topic, the main error upon compiling is Undeclared Identifier: 'Count'
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 500 total points
ID: 35209546
Just calling free may not be a good idea unless you are certain that this is an object owned in list in which case freeing the object deletes the the item index as well other wise you might get access violations later after the delete.

The best way is to use the items delete method instead, remeber to set the items visible property to false first


var
  Obj: TObject;
begin
  for i := dxBarSubItem1.Count - 1 downto 0 do
  begin
    if dxBarsubItem1.Items[i] is TdxBarLargeButton then
    begin
      //check if there is a delete method, this would be better
      Obj := dxBarsubItem1.Items[i];
      dxBarsubItem1.Items[i].Visible := False;  /if the property exists
      dxBarsubItem1.Items.Delete(I);

      
      FreeAndNil(Obj);  //dont use Obj.Free; 

    end;
  end;

Open in new window

0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35209550
Sorry, i did not read the last statement
0
 

Author Comment

by:John86a
ID: 35209551
This almost works, but its still getting errors:
var i: integer;
begin
  for i := dxBarSubItem1.ItemLinks.Count - 1 downto 0 do
  begin
    if dxBarsubItem1.ItemLinks.Items[i] is TdxBarLargeButton then
    begin
      //check if there is a delete method, this would be better
      dxBarsubItem1.Items.Delete(i);
      //or
      TObject(dxBarsubItem1.ItemsLinks.Items[i]).Free; //but this does not remove the nil item from the list

    end;
  end;
end;

Open in new window


Unit1.pas(48): Incompatible types: 'TdxBarLargeButton' and 'TdxBarItemLink'
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35209558

try the items property

dxBarSubItem1.Items.Count
0
 

Author Comment

by:John86a
ID: 35209584
No such property, using devex beta 7.55
0
 

Author Comment

by:John86a
ID: 35209595
  for i := dxBarSubItem1.ItemLinks.Count - 1 downto 0 do
  begin
      TObject(dxBarsubItem1.ItemLinks.Items[i]).Free; //but this does not remove the nil item from the list
  end;

Open in new window


It works like this, but i kind of wanted it to delete only large buttons..
0
 

Author Closing Comment

by:John86a
ID: 35209745
Thanks, I discovered how to detect whether its a largebutton:
if dxBarsubItem1.ItemLinks.Items[i].Item is TdxBarLargeButton then
0

Featured Post

Technology Partners: 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!

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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