Objectname Bugs

Bug reports and errors in the program
Message
Author
KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

Objectname Bugs

#1 Postby KelvinHand » Tue Mar 01, 2011 6:50 pm

Dear Sir,

I created a multiple objects and delete it when done.
However, Not all objects are deleted.

But If i delete one by one using looping with the know name, it is OK.


Code: Select all

procedure Done; stdcall;
var i: Integer;
    s: string;

begin
var
i: integer;
s: string;
 
for i:=0 to ObjectsTotal - 1 do
begin
   s:= ObjectName(i);
   Print(s);
   ObjectDelete(s);
end;




Following is the log that show some object name are blank

Code: Select all


.2011.03.02 07:42:13  Total Objects = 30
.2011.03.02 07:42:13  Object 0 : wtOF_TXT_5D_MP0
.2011.03.02 07:42:13  Object 1 : wtOF_TXT_3D_HR0
.2011.03.02 07:42:13  Object 2 : wtOF_HL_3D_HR0
.2011.03.02 07:42:13  Object 3 : wtOF_TXT_1Hr-VA0
.2011.03.02 07:42:13  Object 4 : wtOF_TXT_1Hr-400
.2011.03.02 07:42:13  Object 5 : wtOF_HL_1Hr+400
.2011.03.02 07:42:13  Object 6 : wtOF_TXT_720_MPL0
.2011.03.02 07:42:13  Object 7 : wtOF_TXT_720_LRL0
.2011.03.02 07:42:13  Object 8 : wtOF_HL_720_HRL0
.2011.03.02 07:42:13  Object 9 : wtOF_TXT_720_MPR0
.2011.03.02 07:42:13  Object 10 : wtOF_TXT_720_LRR0
.2011.03.02 07:42:13  Object 11 : wtOF_HL_720_HRR0
.2011.03.02 07:42:13  Object 12 : wtOF_TXT_IB_HR0
.2011.03.02 07:42:13  Object 13 : wtOF_HL_IB_HR0
.2011.03.02 07:42:13  Object 14 : wtOF_HL_IB_HR1
.2011.03.02 07:42:13  Object 15 :
.2011.03.02 07:42:13  Object 16 :
.2011.03.02 07:42:13  Object 17 :
.2011.03.02 07:42:13  Object 18 :
.2011.03.02 07:42:13  Object 19 :
.2011.03.02 07:42:13  Object 20 :
.2011.03.02 07:42:13  Object 21 :
.2011.03.02 07:42:13  Object 22 :
.2011.03.02 07:42:13  Object 23 :
.2011.03.02 07:42:13  Object 24 :
.2011.03.02 07:42:13  Object 25 :
.2011.03.02 07:42:13  Object 26 :
.2011.03.02 07:42:13  Object 27 :
.2011.03.02 07:42:13  Object 28 :
.2011.03.02 07:42:13  Object 29 :

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Wed Mar 02, 2011 5:12 am

Hello, thank you for your notes, can you please post your full code which creates these objects and deletes them?
Check our other product here:
http://www.forexcopier.com

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#3 Postby KelvinHand » Mon Apr 11, 2011 8:33 pm

Hi,

Sorry for the delay. here is the attached code.

The code in procedure Done - First print all the 9 objects and then
do the delete and not all will be deleted.
Attachments
Test_Indicator.zip
(1.53 KiB) Downloaded 456 times

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

#4 Postby Tantalus » Tue Apr 12, 2011 9:37 am

Try deleting them from the top down:

Code: Select all

for i := ObjectsTotal - 1 downto 0 do
begin
   s:= ObjectName(i);
   Print(s);
   ObjectDelete(s);
end;


This may help to ensure that all objects are deleted. When deleting or closing all open orders this is necessary, so I suspect it will be needed for Objects as well.
Last edited by Tantalus on Wed Apr 13, 2011 10:03 am, edited 1 time in total.
Tantalus Research - Developing 21st Century Trading Systems.

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#5 Postby FT Support » Tue Apr 12, 2011 12:12 pm

I'd not recommend to use this approach, you actually adjust array size within the loop so the iterator can became incorrect.
When you loop through an array it is better to be sure that array elements stay on the same positions but when you delete array items then you cannot be sure about that.
So try to save object names to some another array/list and loop through that list.
Check our other product here:
http://www.forexcopier.com

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

#6 Postby Tantalus » Tue Apr 12, 2011 2:02 pm

That's why I suggested iterating downward instead of upward. That way as the array size decreases, the existing elements retain their original position and index, and you can be sure that the next element you try to delete will still be there.

Here's another alternative:

Code: Select all

for i := 0 to ObjectsTotal - 1 do
begin
s:= ObjectName(0);
Print(s);
ObjectDelete(s);
end;


With this method, you iterate from the lowest to the highest, but you always delete the first element in the array, which is always there (until the array is completely emptied, of course). This will work perfectly as well.
Tantalus Research - Developing 21st Century Trading Systems.

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#7 Postby FT Support » Tue Apr 12, 2011 3:23 pm

Tantalus, you're right, i just want to show "best practice" in deleting items from the array, your approach works fine in tester but can not work in another cases (for example if an array is a "sorted list" and each time you delete an item other items are re-sorted based on different conditions).
Check our other product here:
http://www.forexcopier.com

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#8 Postby KelvinHand » Wed Apr 13, 2011 5:02 am

hi Tantalus,

Thank for your help.
But I could not figure what the logic behind these:
1. Why when printing in a loop using ObjectName(i) that is ok but not
ObjectDelete(ObjectName(i)) ?

2. Why when deleting in the looping, using ObjectName(0) can delete
all the objects wanted ?



Code: Select all

for i := 0 to ObjectsTotal - 1 do
begin
s:= ObjectName(0);
Print(s);
ObjectDelete(s);
end;

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#9 Postby KelvinHand » Wed Apr 13, 2011 5:20 am

Hi,

if i place your ObjectName(0) logic into deleting the needed object. According to my following list, All prefixed with TEST should be deleted and left names[6] and names[7] untouch.

However names[8] seen to not deleted.
Why ???

Code: Select all

  names[0]:= TEST+'VertLine';
  names[1]:= TEST+'HortLine';
  names[2]:= TEST+'TrendLine';
  names[3]:= TEST+'RayLine';
  names[4]:= TEST+'Fib_Retrace';
  names[5]:= TEST+'Fib_Fan';
  names[6]:= 'VertLine2';
  names[7]:= 'Text2';
  names[8]:= TEST+'Text';

 



Code: Select all


    Print('*** Delete Objects *** ' );
    for i:=0 to ObjectsTotal - 1 do
    begin

      s:= ObjectName(0);
      if AnsiContainsStr(s,TEST) then
      begin
        t:=IntToStr(i) + ': '+s+' Deleted!!!';
        Print(t);
        ObjectDelete(s);
      end;

    end;

   

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

#10 Postby Tantalus » Wed Apr 13, 2011 10:01 am

The Object[0] method is to be used only when you are trying to delete all the objects in the array. If you try to skip any of them, it won't work. In the example you gave, you have told FT not to delete [6] and [7]. Because of that it will not work.

To do what you want to do, you should use the other method I listed, which is to iterate from the top down:

Code: Select all

for i := ObjectsTotal - 1 downto 0 do
Tantalus Research - Developing 21st Century Trading Systems.

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#11 Postby KelvinHand » Wed Apr 13, 2011 8:18 pm

Hi Tantalus,

8) Real Cool !!! You had solved my problem.

The MT4 exist the same characteristic.

I should had sticked to MT4 coding, instead of following FT2 example.

But anyway, Big thank to your Enlightment. Without that i could struggle
for months in order to clear the 1000+ objects.


Return to “Bug reports”

Who is online

Users browsing this forum: No registered users and 17 guests