ObjectCreate Failed! Why?

Examples step by step how to make your own automated strategy or user indicator
Message
Author
charvo
Posts: 52
Joined: Tue Dec 04, 2012 1:15 pm

ObjectCreate Failed! Why?

#1 Postby charvo » Thu Dec 27, 2012 1:19 am

Hi, Kelvin or Phil:

Hope that you've enjoyed a great holiday! and also by chance see my post
:)

I am still working on my delphi strategy and stuck at the ObjectCreate command

I only attached the "procedure" instead of the whole program.

the log shows all print() info as success/true except objectcreate only returning [obj NOT created]. and I don't know why. I also used [ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, 0, 0)], not working either...

I also desperately tried 1, 2, and 3 for [OBJPROP_SCREENCOORDS] line, it should not affect objectcreate anyway, and it didn't.

on the currency chart, I do have one RSI and one ATR indicators. will that be the cause?

Many thanks in advance!

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   if ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
   else print('obj NOT created');

   if ObjectSetText(ObjHUDline1, note, 9, 'Arial', colorcode) then print('text set')
   else print('text NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)  then print('corner set')
   else print('corner NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
   else print('timecorrd NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
   else print('pricecorrd NOT set');

end;

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

Re: ObjectCreate Failed! Why?

#2 Postby KelvinHand » Thu Dec 27, 2012 4:40 am

charvo wrote:Hi, Kelvin or Phil:

Hope that you've enjoyed a great holiday! and also by chance see my post
:)

I am still working on my delphi strategy and stuck at the ObjectCreate command

I only attached the "procedure" instead of the whole program.

the log shows all print() info as success/true except objectcreate only returning [obj NOT created]. and I don't know why. I also used [ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, 0, 0)], not working either...

I also desperately tried 1, 2, and 3 for [OBJPROP_SCREENCOORDS] line, it should not affect objectcreate anyway, and it didn't.

on the currency chart, I do have one RSI and one ATR indicators. will that be the cause?

Many thanks in advance!

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   if ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
   else print('obj NOT created');

   if ObjectSetText(ObjHUDline1, note, 9, 'Arial', colorcode) then print('text set')
   else print('text NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)  then print('corner set')
   else print('corner NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
   else print('timecorrd NOT set');

   if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
   else print('pricecorrd NOT set');

end;


Definitely cannot work.
Your declared ObjHUDline1 but never assigned it so ObjHUDline1:=nil;

You MUST assigned in this way:
ObjHUDline1:='Happy New Year';

then it will work.

charvo
Posts: 52
Joined: Tue Dec 04, 2012 1:15 pm

Re: ObjectCreate Failed! Why?

#3 Postby charvo » Thu Dec 27, 2012 11:47 am

ah, i didn't realise this. i thought [ObjectSetText()] is assigning [note] to [ObjHUDline1]......

this is easy, i'll fix it now

Kelvin, you are my life saver! Happy New Year!

KelvinHand wrote:Definitely cannot work.
Your declared ObjHUDline1 but never assigned it so ObjHUDline1:=nil;

You MUST assigned in this way:
ObjHUDline1:='Happy New Year';

charvo
Posts: 52
Joined: Tue Dec 04, 2012 1:15 pm

Re: ObjectCreate Failed! Why?

#4 Postby charvo » Thu Dec 27, 2012 9:55 pm

Hi, Kelvin:

I tried it, but it still not working, the error log is same as before

Please see the attached picture

The error is that [ObjectCreate()] is not performed, or return false.


KelvinHand wrote:Your declared ObjHUDline1 but never assigned it so ObjHUDline1:=nil;

You MUST assigned in this way:
ObjHUDline1:='Happy New Year';

then it will work.

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
var
    ObjHUDline1: string;
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   ObjHUDline1 := 'happy';

     if   ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
     else print('obj NOT created');
     if   ObjectSetText(ObjHUDline1, 'nima', 9, 'Arial', colorcode) then print('text set')
     else print('text NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)    then print('corner set')
     else print('corner NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
     else print('timecorrd NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
     else print('pricecorrd NOT set');


end;
Attachments
Kelvin.JPG
Kelvin.JPG (57.51 KiB) Viewed 12309 times
Last edited by charvo on Thu Dec 27, 2012 11:35 pm, edited 2 times in total.

charvo
Posts: 52
Joined: Tue Dec 04, 2012 1:15 pm

#5 Postby charvo » Thu Dec 27, 2012 11:32 pm

Hi, Kelvin:

I updated my code as below, [ObjectExists()] return true, which confused me a lot. From log, i keep getting "OBJ EXISTS??????!!!!!!" as a result of [objectexists()].

anyway, i tried everything i can think of, my code just don't display anything......

please help, :oops:

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
var
    ObjHUDline1: string;
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   ObjHUDline1 := 'happy';

   if (not ObjectExists(ObjHUDline1)) then
   begin

     if   ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
     else print('obj NOT created');
     if   ObjectSetText(ObjHUDline1, 'nima', 9, 'Arial', colorcode) then print('text set')
     else print('text NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)    then print('corner set')
     else print('corner NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
     else print('timecorrd NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
     else print('pricecorrd NOT set');

   end
   else
     print('OBJ EXISTS??????!!!!!!');

end;

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

#6 Postby KelvinHand » Fri Dec 28, 2012 6:37 am

charvo wrote:Hi, Kelvin:

I updated my code as below, [ObjectExists()] return true, which confused me a lot. From log, i keep getting "OBJ EXISTS??????!!!!!!" as a result of [objectexists()].

anyway, i tried everything i can think of, my code just don't display anything......

please help, :oops:

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
var
    ObjHUDline1: string;
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   ObjHUDline1 := 'happy';

   if (not ObjectExists(ObjHUDline1)) then
   begin

     if   ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
     else print('obj NOT created');
     if   ObjectSetText(ObjHUDline1, 'nima', 9, 'Arial', colorcode) then print('text set')
     else print('text NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)    then print('corner set')
     else print('corner NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
     else print('timecorrd NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
     else print('pricecorrd NOT set');

   end
   else
     print('OBJ EXISTS??????!!!!!!');

end;


//----------------------------------------------------------
change to HUDprojector1(..., TDatetime, double)
Use HUDprojector1(..., Time(0), High(0)) to call again and verify the
procedure is working.

Looking into the following to see how to set label.
http://forextester.com/forum/viewtopic. ... ht=objtext

ObjectSet(ObjName,OBJPROP_SCREENCOORDS,1);
to change to screen coordinate (X,Y) instead of time/price coordinate


Code: Select all





procedure HUDprojector1(note:string; colorcode: Tcolor; X,Y: integer);
var
    ObjHUDline1: string;
begin
   SetCurrencyAndTimeframe(sym[1], 60);

   ObjHUDline1 := 'happy';

   if not(ObjectExists(ObjHUDline1)) then
      ObjectCreate(ObjHUDline1, obj_Text, 0, 0, 0);


   ObjectSetText(ObjHUDline1, note, 9, 'Arial', colorcode);

   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS, 1);

   ObjectSet(ObjHUDline1, OBJPROP_TIME1, X);
   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,Y);

  {=============
   // text alignment
  tlTop           = 0;
  tlCenter        = 1;
  tlBottom        = 2;
  ============}
  ObjectSet(ObjHUDline1, OBJPROP_VALIGNMENT, tlBottom);

  {===============
    taLeftJustify   = 0;
    taRightJustify  = 1;
    taCenter        = 2;
  ===============}
  ObjectSet(ObjHUDline1, OBJPROP_HALIGNMENT, taRightJustify);

  {====================================
   OBJPROP_SCRVALIGNMENT = 0 – no vertical alignment
   OBJPROP_SCRVALIGNMENT = 1 –align to bottom
   OBJPROP_SCRVALIGNMENT = 2 –align to top
   ====================================}
  ObjectSet(ObjHUDline1, OBJPROP_SCRVALIGNMENT, 1);

 {====================================
  OBJPROP_SCRHALIGNMENT = 0 – no horizontal alignment
  OBJPROP_SCRHALIGNMENT = 1 –align to right
  OBJPROP_SCRHALIGNMENT = 2 –align to left
====================================}
  ObjectSet(ObjHUDline1, OBJPROP_SCRHALIGNMENT, 1);




On the call to HUDprojector1(infonote1, clGreen, 1000, 90);

Try to set the X & Y to 20,20 to top left so that visible then adjust X, Y value to move the label to the extreme top right visible position.

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

#7 Postby KelvinHand » Fri Dec 28, 2012 10:44 am

KelvinHand wrote:
charvo wrote:Hi, Kelvin:

I updated my code as below, [ObjectExists()] return true, which confused me a lot. From log, i keep getting "OBJ EXISTS??????!!!!!!" as a result of [objectexists()].

anyway, i tried everything i can think of, my code just don't display anything......

please help, :oops:

Code: Select all

procedure HUDprojector1(note:string; colorcode: Tcolor; timecoord: integer; pricecoord: integer);
var
    ObjHUDline1: string;
begin

   if SetCurrencyAndTimeframe(sym[1], 60)  then print(sym[1] + ' is set for HUD().')
   else print('sym[1] is NOT set!');

   ObjHUDline1 := 'happy';

   if (not ObjectExists(ObjHUDline1)) then
   begin

     if   ObjectCreate(ObjHUDline1, OBJ_TEXT, 0, Time(0), High(0))  then print('obj created')
     else print('obj NOT created');
     if   ObjectSetText(ObjHUDline1, 'nima', 9, 'Arial', colorcode) then print('text set')
     else print('text NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS,3)    then print('corner set')
     else print('corner NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_TIME1, timecoord)  then print('timecorrd set')
     else print('timecorrd NOT set');
     if   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,pricecoord) then print('pricecorrd set')
     else print('pricecorrd NOT set');

   end
   else
     print('OBJ EXISTS??????!!!!!!');

end;


//----------------------------------------------------------
change to HUDprojector1(..., TDatetime, double)
Use HUDprojector1(..., Time(0), High(0)) to call again and verify the
procedure is working.

Looking into the following to see how to set label.
http://forextester.com/forum/viewtopic. ... ht=objtext

ObjectSet(ObjName,OBJPROP_SCREENCOORDS,1);
to change to screen coordinate (X,Y) instead of time/price coordinate


Code: Select all





procedure HUDprojector1(note:string; colorcode: Tcolor; X,Y: integer);
var
    ObjHUDline1: string;
begin
   SetCurrencyAndTimeframe(sym[1], 60);

   ObjHUDline1 := 'happy';

   //if not(ObjectExists(ObjHUDline1)) then
   ObjectDelete(ObjHUDline1);
      ObjectCreate(ObjHUDline1, obj_Text, 0, 0, 0);


   ObjectSetText(ObjHUDline1, note, 9, 'Arial', colorcode);

   ObjectSet(ObjHUDline1, OBJPROP_SCREENCOORDS, 1);

   ObjectSet(ObjHUDline1, OBJPROP_TIME1, X);
   ObjectSet(ObjHUDline1, OBJPROP_PRICE1,Y);

  {=============
   // text alignment
  tlTop           = 0;
  tlCenter        = 1;
  tlBottom        = 2;
  ============}
  ObjectSet(ObjHUDline1, OBJPROP_VALIGNMENT, tlBottom);

  {===============
    taLeftJustify   = 0;
    taRightJustify  = 1;
    taCenter        = 2;
  ===============}
  ObjectSet(ObjHUDline1, OBJPROP_HALIGNMENT, taRightJustify);

  {====================================
   To align Text to Window Top/Bottom
   * 0 – top corner
   * 1 – bottom corner
   ====================================}
  ObjectSet(ObjHUDline1, OBJPROP_SCRVALIGNMENT, 1);

   {====================================
   To align Text to Window left/right
   * 0 – left corner
   * 1 – right corner
 ====================================}
  ObjectSet(ObjHUDline1, OBJPROP_SCRHALIGNMENT, 1);
end;



On the call to HUDprojector1(infonote1, clGreen, 100, 20);




Attached Working Demo
Attachments
Strategy_RC1.dll
(356 KiB) Downloaded 387 times
Last edited by KelvinHand on Fri Dec 28, 2012 7:56 pm, edited 2 times in total.

charvo
Posts: 52
Joined: Tue Dec 04, 2012 1:15 pm

#8 Postby charvo » Fri Dec 28, 2012 2:53 pm

Thanks a million, Kelvin.

I ran home and apply your fix. It is working now. I'm still 'trial and error' all the parameters to gain more understanding on objectcreate()......

you remind me of the song by Michael Bolton -- "how am i supposed to live without you" :wink:

KelvinHand wrote:On the call to HUDprojector1(infonote1, clGreen, 100, 20);


Attached Working Demo

violajsilver
Posts: 5
Joined: Mon May 09, 2016 11:42 pm

Re: ObjectCreate Failed! Why?

#9 Postby violajsilver » Tue May 10, 2016 12:23 am

Nice post. This helped me to solve a problem.


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 1 guest