Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Color in Grid Issue 1

Scott24x7

Programmer
Jul 12, 2001
2,789
10
38
JP
1725884529217.png

I occasionally get this message popping up (I'm of course using grids on a form which use dynamicbackcolor property to highlight records for this appearance:

1725885390482.png

The appearance is what I expect, so this "error message" doesn't seem to have any impact or issue.
Is there some way to suppress this "alert". It doesn't trigger the same VFP Error handling, and is more informational or "warning", but it's annoying.
The usual attributes like SET TALK OFF are in place, so I'm stumped.
Anyone ever see this?
 
Dynamic* properties are string expression:
Code:
 grid.column.dynamicbackcolor="IIF(.t. , RGB(0, 0, 128), RGB(255, 255, 255))"
 
Dynamic* properties are string expression:
Code:
 grid.column.dynamicbackcolor="IIF(.t. , RGB(0, 0, 128), RGB(255, 255, 255))"
Absolutely right. It expects a string, so if it's occasionally throwing that message, something in the string that is tied to the current record is likely not giving an expected value.

For example, if the string says "IIF(somefield = [xyz], RGB(0, 0, 128), RGB(255, 255, 255))", the expression somefield = [xyz] would return invalid at runtime if somefield is not a string... such as a null.

@Scott24x7, can you show us what the expression is?
 
Yeah, that's essentially what I have.
That's why this message is odd.
The exact code in the column's DynamicBackColor property within the grid is :
Code:
IIF( COMPANYFACILITYGRID.LEDGERCONTROL, RGB(255,255,255), RGB(225,247,255))

Where the value for LEDGERCONTROL is either .T. or .F. and is established to alternate after grid cursor is created, which allows for the alternating color.
My issue isn't with the control displaying the way that I want it to. The issue is I occasionally get this very strange "warning" pop up, which is a distraction while working in the system. Like I said, I'm happy to just suppress this from appearing, since it seems to have no other impact on the function or operation of the grids controls on the screen. (There are about 8 in total, and they all display fine even when this "warning" appears.

The grid, including the LedgerControl field is built in the REFRESH() of the grid control:

Code:
IF NOT This.nGridRec = COMPANYGRID.COMPANYID OR NOT USED("COMPANYFACILITYGRID")
    This.RecordSource = ""
*
    SELECT FACILITYNAME, FACILITYCOUNTRY, FACILITYCITY, FACILITYID, COMPANYID, .F. AS LEDGERCONTROL, "FACILITY" AS TABLESOURCE, RECNO() AS RECORDSOURCE;
        FROM FACILITY;
        WHERE COMPANYGRID.COMPANYID = FACILITY.COMPANYID;
        INTO CURSOR COMPANYFACILITYGRID READWRITE ORDER BY FACILITYNAME
*
* Make some indexes for later use
*
    SELECT COMPANYFACILITYGRID
    INDEX ON BINTOC(COMPANYFACILITYGRID.FACILITYID) TAG FACILITYID
*
    SELECT COMPANYFACILITYGRID
    INDEX ON UPPER(FACILITYCOUNTRY)+UPPER(FACILITYNAME) TAG FACORDER
*
    SELECT COMPANYFACILITYGRID
    SET ORDER TO FACORDER
    GO TOP
    llLedgerControl = .F.
    DO WHILE NOT EOF()
        REPLACE COMPANYFACILITYGRID.LEDGERCONTROL WITH llLedgerControl
        llLedgerControl = NOT llLedgerControl
        SKIP
    ENDDO
    GO TOP
*
    This.RecordSource = "COMPANYFACILITYGRID"
ENDIF
*
This.nGridRec = COMPANYFACILITYGRID.COMPANYID
*
lnGridCount = RECCOUNT("COMPANYFACILITYGRID")
*
IF lnGridCount = 1
    This.Parent.lblFacilityCount.Caption = ALLTRIM(STR(lnGridCount))+" Facility"
ELSE
    This.Parent.lblFacilityCount.Caption = ALLTRIM(STR(lnGridCount))+" Facilities"
ENDIF
*
IF lnGridCount = 0
    ThisForm.Pageframebase1.Pagebase3.lPageEnabled = .F.
ELSE
    ThisForm.Pageframebase1.Pagebase3.lPageEnabled = .T.
ENDIF
*
IF lnGridCount > 0
    SELECT FACILITY
    lcCurOrder = ORDER()
    SET ORDER TO FACILITYID
    SEEK BINTOC(COMPANYFACILITYGRID.FACILITYID)
    SET ORDER TO (lcCurOrder)
ENDIF

So note that the value is set to alternate .T. or .F. which is what drives the dynamic back color.
As mentioned, since they all display as expected, I'm really just looking to suppress this message since it has no impact on the operation of the application. it's just an annoying distraction.
 
Last edited:
Maybe you end on a valid expression and thus get the colors you want, but at point it's not (yet) valid? Look into what you have in the DynamicBackColor property at the time of the message.

The title of the messagebox suggests, this is not a VFP system message, but comes from your application "GDCE -DCide", so it is from the error handler, likely. In fact, if you have a non working expression (one that doesn't result in a color value - technically an integer value - then this does throw an error.) It's error 1759.

As your error handling obviously catches it, you may make an exception to not display an error messagebox in that special case, for error 1759 and that form. But I think it will even be easier to just fix the expression and set it early enough to work properly all the time. Or, indeed, set the expression later. Usually, the expression will be an IIF or ICASE that decides based on values of the grid alias, so don't set the DynamicBackcolor before you set the grid recordsource, that makes it invalid for the time until you set the recordsource.

Edit: I wrote this before you posted your expression. Notice the grid is very sensitive, if just for a briwf moment ´while you requery the grid recordsource the cursor accessed in your DanamicBackcolor expression does not exist, that error is thrown. So if you unbind the grid and set grid.recordsource="" for requering it you also need to set the DanmicBackColor empty and only set it back after the cursor is requeried and the grid recordsource is set back. Even though in the end both the recordsource and dynamicbackcolor will be the same, you have top do that.

The simplest way to not have that problem is creating a grid cursor you never recreate, but instead ZAP and refill, then you also don't need to unset and reset the DynamicVBackColor or other Dynamic... proiperties depending on the grid cursor.

Notice: When you do an SQL Query INTO CURSOR and reuse the name of the grid and think that there is no moment ever the cursor alis does not exist, because it exists before and after, you still have not uderstood that this very brief moment where the new resultset is built from the query, the grid has a problem known as "grid goes blank" and grid reconstruction and this problem of the DynamicBackColor is just one more aspect of the same problem.
 
Last edited:
Chris,
Very tricky. Because I can't "trap" the error, because it's not a VFP "error", in fact it's the only control I've seen of near 40 years of Fox programming that doesn't have an "error code" (I have a full error handling routine that captures all the state at the tom of an error, for instance, if I had a "record out of range" error, that would trigger Fox's error routine, and I'd get an error message that stops all others. The closest thing I can think of to it is the equivalent of "SET SAFETY" where it will ask do you want to overwrite an existing file (if you have SET SAFETY ON). You can suppress the warning with SET SAFETY OFF. But this is a different issue, and I can find nothing regarding the message in the help file. It doesn't generate an error code like if a record is out of range, you get an error code of 5 "Record Out of Range". This doesn't create that kind of error code or error message. So I've no idea how to suppress it, or capture it for exception handling.
 
Scott: Why on Earth would a VFP system "warning" have a title "GDCE -Dcide".
It is documented as ERROR 1759. That's a fact, not a guess.
 
Ah... I have found the error in the help file.
I missed the "name". BUT it's not particularly helpful in this case, and Chris, I see your point about something oddly "very momentarily" causing the issue.
BUT, since I have an error number (1759) I can suppress it in the error handler and as a short term fix, that may be ok for now until I rework this. It is a VERY complex series of related grids, so change in record pointer in 1 grid can change multiple grids on the same form. Let me try this.

Error Messages Listed Alphabetically
 
Scott24x7, if you close rowsource for grid, it's good way, how to prevent problems, set all column's properties again.
 
You could also change the IIF Expression to include the case of the brief moment the cursor COMPANYFACILITYGRID does not exist.

Code:
ICASE(VARTYPE("COMPANYFACILITYGRID.LEDGERCONTROL")="L",COMPANYFACILITYGRID.LEDGERCONTROL, RGB(255,255,255), RGB(225,247,255), RGB(255,255,255))

Code:
IIF(VARTYPE("COMPANYFACILITYGRID.LEDGERCONTROL")="L",Iif(COMPANYFACILITYGRID.LEDGERCONTROL, RGB(255,255,255), RGB(225,247,255)), RGB(255,255,255))

Yet another correction:
Code:
IIF(VARTYPE(COMPANYFACILITYGRID.LEDGERCONTROL)="L",Iif(COMPANYFACILITYGRID.LEDGERCONTROL, RGB(255,255,255), RGB(225,247,255)), RGB(255,255,255))
It has to be either TYPE("COMPANYFACILITYGRID.LEDGERCONTROL") or VARTYPE(COMPANYFACILITYGRID.LEDGERCONTROL).

The best solution is to use the "safe select" technique for grid cursor, that way you also never need to reset anything in a grid, no recordsource, dynamic properties and column controlsources. Google "VFP safe select grid" and you find several pages describing it.
 
Last edited:
Chris,
Because it's taking the title from the the MAIN system Title Bar.
1725890479244.png

I have taken control of the window title, and this error message is just reflecting what is there. The application is built to reflect modern ribbon system, and so I've used the ability within VFP to have more control over the top line (note that things like the usual menu and the Minimize, Open, Close window buttons are not from Windows, rather from the application.

1725890710521.png

VFP is just using that as the default style for this warning message. This is not generated with something like "MESSAGEBOX", and one thing you will note is that error window has the Fox logo on it, and not the globe icon that you can see just under the GDCE - DCide in the snippet of the ribbon view which is the MAIN window.
 
Hey Chris,
That improvement to the IIF did the trick. I am viewing this as a bandaid, and short term fix. The safe select is interesting, but will require a full refit of the existing grids on the screen, which I know are not optimal, and there is a plan to address it longer term, but this fixes my issue for "today", and the safe select is a "tomorrow problem".
This is good though, thanks for that!
 
That's if you want to use native windows "window". Since I'm building this as a Ribbon and I don't want any of the "legacy" stuff following it around, I have made my own windows topline.
 

Part and Inventory Search

Sponsor

Back
Top