Solved

DevExpress - Deleting a list of subitems..

Posted on 2011-03-24
9
950 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
  • 5
  • 4
9 Comments
 
LVL 32

Expert Comment

by:ewangoya
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:
ewangoya 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 32

Expert Comment

by:ewangoya
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:ewangoya
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

856 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