tab control: currform.field.UPDATEFORECOLOR

Hi, I have a new problem with a tab control. I try to format negative amounts with UPDATEFORECOLOR(255) in the OnFormat - Trigger (on a Tab control form). If I run the form the following error appears: “The form doesn’t know control 1000000018.” (from German!). Control 1000000018 ist the control which I want to format. On a form without tab control this method works! It seems there are a lot of restrictions if I work with a tab control [xx(]. Or am I wrong? Andre

No problem here. I have a control in a tab where the “Name” property is “Betrag”, and in its OnFormat trigger I put the code IF Betrag < 0 THEN CurrForm.Betrag.UPDATEFORECOLOR(255); Works just fine. What code did you use? Did you use the control ID instead of the Name? Did you use the OnFormat trigger of the control or another one? If I use the tab’s trigger, I get an error too, especially if the control is not on the active tab [:p]

Hi Heinz, if it works on your system it should work on my system too! This is my code in the OnFormat- Trigger of the textbox ‘BudNetDiff’:


**OnFormat(VAR Text : Text[1024];)**
 IF (NetJahrBudVgl-NetJahrBud) < 0
   THEN CurrForm.BudNetDiff.UPDATEFORECOLOR(255)
   ELSE CurrForm.BudNetDiff.UPDATEFORECOLOR(0);

Perhaps there is another reason for this error: My form is an unbound form (budget comparison). In the OnInit- Trigger (form) I call a function to calculate all the fields. Is it possible that Attain first formats the fields (now empty) and then runs the function? I can’t check this with the debugger. The error appears always direct after calling the function. If I remove the above code the form runs. Andre

Hi Heinz, thank you for helping me. As I wrote my last posting I thought: ‘Perhaps I should use the OnOpenForm- trigger to call the function!’. And - it works! My amount is red! Andre

Andre, I don’t quite understand what the problem was, but I’m glad that you cold solve it [8D] Btw, I work with Fin 2.60, I haven’t laid my hands on Attain yet [;)] If your OnInit trigger only calculated values without accessing any controls (which is not allowed in OnInit), then there shouldn’t be a difference between putting this code in OnInit or in OnOpenForm. The control and its forecolor are accessed in the OnFormat trigger only, which shouldn’t be a problem. If, however, you accessed controls in your initialization code, then of course it does make a difference. I will experiment a bit, but I’d also be interested in the details of your solution.

Just did a bit of testing, and Navision behaved as expected. I created an unbound form with two global variables and a text box that shows their difference. The OnFormat trigger paints the box red when the diff is < 0. Initializing the two variables in the OnInit trigger works exactly like doing so in OnOpenForm: No problem [8D] I’d guess that something is wrong either with Attain or with your initialization code [:D]

Hi Heinz, here is my code (moved from OnInitForm to OnOpenForm):


"!Budget".SETRANGE("!Budget"."Bis Datum",CALCDATE('+LJ',DatumBis));
"!Budget".FIND('+');
BName:= "!Budget".Name;
"!Budget II".COPYFILTERS("!Budget");
"!Budget II".FIND('-');
"BName II":= "!Budget II".Name;

CalcCells; //call the function to fill the fields

In OnInitForm it doesn’t work, in OnOpenForm it works. I don’t know why, it doesn’t matter [:D]. Andre

Looks mostly harmless, but what does CalcCells do??? Maybe call CurrForm.UPDATE? [:p]

Hi Heinz, here is small part of my CalcCells- function:


CalcCells()
DatumVonVJ:= CALCDATE('-1J',DatumVon);
DatumBisVJ:= CALCDATE('+LJ',DatumVonVJ);

If I debug: The error appears here! 
With CalcCells in OnInitForm!
No variable is calculated!
Once again: The error is: "The form doesn't know control 1000000018." 
Strange!

CurrForm.CAPTION:='P/L (Reportform) Budget: ' +"!Budget".Name+ ' Datum (Act.): ' +FORMAT(DatumVon)+ '-' +FORMAT(DatumBis)+
                  ' Datum (VJ): ' +FORMAT(DatumVonVJ)+ '-' +FORMAT(DatumBisVJ);

"!Konto".SETCURRENTKEY("!Konto".reportposition,"!Konto"."No.");

"!Konto".SETRANGE("!Konto".reportposition,'NET');
IF "!Konto".FIND('-') THEN;
REPEAT
 "!Konto".SETRANGE("!Konto"."Date Filter",DatumVon,DatumBis);
 "!Konto".SETRANGE("!Konto"."Budget Filter","!Budget".Name);
 "!Konto".CALCFIELDS("!Konto"."Budget at Date");
  **NetJahrBud**:= NetJahrBud + "!Konto"."Budget at Date";

 "!Konto".SETRANGE("!Konto"."Budget Filter","!Budget II".Name);
 "!Konto".CALCFIELDS("!Konto"."Budget at Date");
  **NetJahrBudVgl**:= NetJahrBudVgl + "!Konto"."Budget at Date";
 
 "!Konto".SETRANGE("!Konto"."Date Filter",DatumVonVJ,DatumBisVJ);
 "!Konto".CALCFIELDS("!Konto"."Balance at Date");
  NetJahrVJ:= NetJahrVJ + "!Konto"."Balance at Date";
UNTIL "!Konto".NEXT = 0;
...

And now my field: BudNetDiff SourceExpr: (NetJahrBudVgl-NetJahrBud)


OnFormat(VAR Text : Text[1024];)
  IF (NetJahrBudVgl-NetJahrBud) < 0
    THEN CurrForm.BudNetDiff.UPDATEFORECOLOR(255)
    ELSE CurrForm.BudNetDiff.UPDATEFORECOLOR(0); 

Perhaps the OnFormat- trigger doesn’t work together with OnInitForm if there is a function. I don’t know! The OnOpenForm- trigger works [8D]! Andre

quote:


Originally posted by xorph You are setting the form’s title bar here, but in OnInit there is no form and no title bar yet! [:0] More precisely, the controls that make up the form and all its contents have not been created at this point. So at this point in time, there is no caption you can set. I suppose that the label or whatever windows object that is used for displaying the caption has ID 1000000018 (this number sounds very much like an internal one).


Sure, I can set the caption at this time. I have all information I need (Budget.Name, DatumVon, DatumBis). I wrote earlier: If I remove the OnFormat- Code the form runs. The Control 1000000018 is my textbox which I want to format.

quote:


Originally posted by xorph I’d bet half my salary that your initialization code will work in OnInit once you remove this single line - unless, of course, you have something similar hidden elsewhere [:D] Ok, thinking about it, half my salary is way too much… How about an Euro? [:p]


Normally I don’t bet [8D]. But in this case I’ll send you my account no. So you can transfer the money. You can also send a check [;)]. I wish you a nice weekend Andre

Andre, I just deleted a posting in which I suggested that setting the caption was the cause of the error because in OnInit there is no caption available. If you have read it already, please forget it. I did some more testing and it turned out that setting the caption is only a problem when you try and set the caption 1) from OnInit and 2) there is an OnFormat trigger present for a text box. Just as you described. Without the trigger, it works. This is really, really weird. [?][?][?]

Too bad, you had already read my then-deleted posting. Sorry. But actually, I would have won the bet, so I’m going to send you my account number by email. [;)] If you remove the CurrForm.CAPTION := … line, your code will work in OnInit, and this (and only this) is what I had placed my bet on [8D] I tried it again with a very simple form, placing CONFIRMs in the triggers to see what’s really going on. With or without setting the caption in OnInit, the defined sequence of triggers is strictly followed. It doesn’t matter if you call a function or set the caption directly in the trigger. I had suspected that setting the caption causes an implicit refresh of the entire form with a call to OnFormat (which would then cause the error because the text box has not been created in OnInit), but this is not the case. It seems like an internal problem, read: bug, in the core routines that create and draw a form. Strange. Really strange. Have nice weekend,

Hi Heinz, it seems I’ve (We’ve) found a bug in Attain/NF. I’m curious if somebody has an anwser to your thread regarding this bug. bye Andre