Solved

DevExpress - Deleting a list of subitems..

Posted on 2011-03-24
9
949 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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…

810 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