?
Solved

DevExpress - Deleting a list of subitems..

Posted on 2011-03-24
9
Medium Priority
?
956 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 2000 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 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