List browser index quirks - PC Mac

From Vectorlab
Jump to: navigation, search

The present script is a List Browser dialog dedicated to experiment the quirks between PC and Mac indexes when using SetLBItemInfo. Apparently the index required is 0-based on Mac and 1-based on PC (valid for VW 1200+, not from VW 1300+). By Orso

Thank you Orso for this code. It is a big help in getting started with the List Browsers. The problem you describe seems indeed to be fixed for VW 2008. Use the PC code on both Mac and PC to get a proper result. Gerard Jonker


The scripts creates a dialog with a list browser, three columns and two buttons. Both buttons load a set of 5 row numbers starting from 0, as required by the List Browser.

  • The Mac button will load using 0-based index.
    correct result on a mac: 5 rows from 0-4.
    wrong result on a PC: the last row won't be complete.
  • The PC button will load using 1-based index.
    wrong result on a mac: the second number won't load, nor the definition "PC".
    correct result on a PC: five rows from 0-4.

Both buttons use the same subroutine InsertRow. This routine when called:

  • checks the count of rows already existing in the list browser lb,
rowIndx := GetNumLBItems(d, lb);

rowIndx is returned by the routine GetNumLBItems. This needs:

  • d: the ID of the dialog
  • lb: the ID of the list browser.
  • adds a row at the end of the list browser. This also loads the first cell of the row. We write the row index in this cell.
newRowIndx := InsertLBItem(d, lb, rowIndx, Concat(rowIndx));
InsertLBItem takes:
  • d: the ID of the dialog
  • lb: the ID of the list browser.
  • rowIndx: previously defined.
  • some text to place into the cell. We place here the defined rowIndx.
  • determines the new row index where to insert cell values <code=vss>InsertRow(gD, cLB, 1);</code=vss> used by both buttons in the dialog setup.
newRowIndx := newRowIndx - detract;
CASE detract OF
0: explan := 'PC';
1: explan := 'Mac';
  • newRowIndx is the row index to be used for inserting the values in the columns of the newly created row.
  • detract is a value to make this work according to the platform. Normally you would use a platform switch, but here it won't show the error. Detract is defined manually, passing it as parameter from the routine call later on, on clicking the buttons.
  • defines the explanation explan, which is displayed on the third column: the platform under which it should work
  • Load the cells, one by one (remember that the first one was already loaden with InsertLBItem).
  • <code=vss>temp_b := SetLBItemInfo(d, lb, newRowIndx, 1, Concat(newRowIndx), 0);

    temp_b := SetLBItemInfo(d, lb, newRowIndx, 2, explan, 0);</code=vss>

    Now we load the row with all column values, using newRowIndx.

    Below you can see what happens running this script on a Mac or a PC. The images below are generated by the same script: first click on the button "Mac", then on the button "PC". Please also note the difference in the dialog dimension and proportions.

    LBquirksMac.png LBquirksPC.png

    Dialog browser test

    List browser quirks with SetLBItemInfo indexes between Mac and PC.
    PROCEDURE testLB_index;
        cLBWidth = 45; { width in characters }
        cLBHeight = 22; 
        kLBControlTypeNone = 1;
        kLBDisplayTypeText = 2;
        cLB = 10;
        cPu_LoadRowsMac = 11;
        cPu_LoadRowsPC = 12;
        cPu_DeleteRows = 13;
        platform, gD, gDlogResult : INTEGER;
        gIsMac : BOOLEAN;
        i, n : INTEGER;
        temp_r : REAL;
        temp_i : INTEGER;
        temp_s : STRING;
        temp_b : BOOLEAN;
        { ************************************************* }
        { builds up the layout }
        FUNCTION Dialog_Layout: INTEGER;
                dialogID : INTEGER;
                dialogID := CreateLayout('Test List Browser indexes', TRUE, 'Exit', '');
                CreateLB(dialogID, cLB, cLBWidth, cLBHeight);
                CreatePushButton(dialogID, cPu_LoadRowsMac, 'Load 5 rows with Mac index (0-based)');
                CreatePushButton(dialogID, cPu_LoadRowsPC, 'Load 5 rows with PC index (1-based)');
                CreatePushButton(dialogID, cPu_DeleteRows, 'Delete all');
                SetFirstLayoutItem(dialogID, cLB);
                SetBelowItem(dialogID, cLB, cPu_LoadRowsMac, 0, 0);
                SetBelowItem(dialogID, cPu_LoadRowsMac, cPu_LoadRowsPC, 0, 0);
                SetBelowItem(dialogID, cPu_LoadRowsPC, cPu_DeleteRows, 0, 0);
                AlignItemEdge(dialogID, cPu_LoadRowsMac, 1, 100, 0);
                AlignItemEdge(dialogID, cPu_LoadRowsPC, 1, 100, 0);
                AlignItemEdge(dialogID, cLB, 1, 101, 1);
                AlignItemEdge(dialogID, cPu_DeleteRows, 1, 101, 1);
                Dialog_Layout := dialogID;
        { ************************************************* }
        { dialog driver }
        PROCEDURE Dialog_Events(VAR item:LONGINT; data:LONGINT);
            result : BOOLEAN;
            i, n : INTEGER;
            { **************************** set up a 3 columns LB }
            PROCEDURE Make3col_LB(listBrowser: LONGINT; colTitle0, colTitle1, colTitle2: STRING; colWidth: INTEGER);
                    i, colNum, rowNum : INTEGER;
                    colTitle : ARRAY[1..3] OF STRING;
                	colTitle[1] := colTitle0;
                	colTitle[2] := colTitle1;
                	colTitle[3] := colTitle2;
                	FOR i := 0 TO 2 DO BEGIN
                    	colNum := InsertLBColumn(gD, listBrowser, i, colTitle[i+1], colWidth);
                    	temp_b := SetLBControlType(gD, listBrowser, colNum, kLBControlTypeNone);
                    	temp_b := SetLBItemDisplayType(gD, listBrowser, colNum, kLBDisplayTypeText);
                    EnableLBColumnLines(gD, listBrowser, TRUE);
            { **************************** insert 1 row in a LB }
            PROCEDURE InsertRow(d, lb: LONGINT; detract: INTEGER);
                    rowIndx, newRowIndx : INTEGER;
                    explan : STRING;
                    rowIndx := GetNumLBItems(d, lb);
                    newRowIndx := InsertLBItem(d, lb, rowIndx, Concat(rowIndx)); 
                    newRowIndx := newRowIndx - detract;
                    { SetLBItemInfo is 0-based on Mac, 1-based on PC }
                    CASE detract OF
                    0: explan := 'PC';
                    1: explan := 'Mac';
                    temp_b := SetLBItemInfo(d, lb, newRowIndx, 1, Concat(newRowIndx), -1);
                    temp_b := SetLBItemInfo(d, lb, newRowIndx, 2, explan, -1);
                    temp_b := RefreshLB(d, lb);
            CASE item OF
                    Make3col_LB(cLB, 'Row index', 'New Row Indx', 'Type', 90);
                    FOR i := 1 TO 5 DO
                        InsertRow(gD, cLB, 1);
                    FOR i := 1 TO 5 DO
                        InsertRow(gD, cLB, 0);
                    temp_b := DeleteAllLBItems(gD, cLB);
            END; {of item}
    { *********************** MAIN ************************** }
        GetVersion(temp_i, temp_i, temp_i, platform);
        gIsMac := (platform = 1);
        gD := Dialog_Layout;
        IF VerifyLayout(gD) THEN
            gDlogResult := RunLayoutDialog(gD, Dialog_Events);