Solved

DevExpress - Deleting a list of subitems..

Posted on 2011-03-24
9
944 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
 
LVL 32

Expert Comment

by:ewangoya
ID: 35209550
Sorry, i did not read the last statement
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 89
NotAlone Challenge 20 72
Dev Express grid collapse 2 35
Re-position sub-options beneath the TAB 7 43
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now