This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] BOOSTXL-K350QVG-S1:有关定义 grlib ListBox 小部件的问题。 编译错误。

Guru**** 1137340 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1106894/boostxl-k350qvg-s1-question-about-defining-a-grlib-listbox-widget-having-compile-errors

器件型号:BOOSTXL-K350QVG-S1

#ifndef SCREEN_H_
#define SCREEN_H_

#include <stdint.h>
#include <stdbool.h>
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "grlib/slider.h"
#include "grlib/listbox.h"
#include "images.h"


// default variable names
extern tCanvasWidget g_psPanels[];
extern tWidget *infoPage;
extern tWidget *logPage;

extern uint32_t g_ui32Panel;
extern char *g_pcPanei32Names[];
extern tPushButtonWidget g_sPrevious, g_sNext;
extern tCanvasWidget g_sTitle, g_sDashboard,  g_sCAN;
extern tListBoxWidget g_sMenu;

...

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <Screen.h>
#include "driverlib/sysctl.h"
#include "drivers/Kentec320x240x16_ssd2119_spi.h"
#include "drivers/touch.h"
#include "images.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "grlib/slider.h"
#include "grlib/listbox.h"



char* error = "test";
char** ppcText = &error;

// Forward declaration of functions
void OnDashboardPaint(tWidget *psWidget, tContext *psContext);
void OnErrorLogPaint(tWidget *psWidget, tContext *psContext);
void OnCanPaint(tWidget *psWidget, tContext *psContext);



// The panel that is currently being displayed.
uint32_t g_ui32Panel;


// An array of canvas widgets, one per panel.  Each canvas is filled with
// black, overwriting the contents of the previous panel.
tCanvasWidget g_psPanels[] = {
        CanvasStruct(0, 0, &g_sDashboard, &g_sKentec320x240x16_SSD2119, 0, 0,
                320, 240, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
        CanvasStruct(0, 0, &g_sMenu, &g_sKentec320x240x16_SSD2119, 0, 0, 320,
                240, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
        };


// The list of panels being displayed on screen
Canvas(g_sDashboard, g_psPanels, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 0, 320,
       240, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnDashboardPaint);


//************************************************************************
//"../Screen.c", line 66: error #28: expression must have a constant value
//************************************************************************
ListBox(g_sMenu, g_psPanels + 1, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 0, 320,
       240, LISTBOX_STYLE_WRAP|LISTBOX_STYLE_LOCKED, 0, 0, 0, 0, 0, 0, ppcText,
       8, 0, OnErrorLogPaint);

Canvas(g_sCAN, g_psPanels + 2, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 0, 320,
       240, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnCanPaint);
       
...

我没有找到很多有关列表框的示例、因此这个基本问题。  

我在 TM4C 板上使用此显示屏、 并尝试 在第二个屏幕上添加列表框控件。 我 将带有空字符串表的 ListBox 定义为第二个 CanvasStruct. 现在、我得到这个"表达式必须有一个常量值错误"。 我出了什么问题?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="503376" URL"~μ C/support/microriors/arm-based microset-group/arm -based microriors/f/arm based 微控制器-forume/1106894/boostxl-k350qvg-s1-question-about -definitioning-a-grlib-listbox-widget-hing-errors"]现在必须获取此表达式的常量值[。]

    从尝试代码片段开始、错误来自尝试将 ppcText 传递到 ListBox 宏、该宏将为 g_sMenu 设置初始化程序

    如果您更换:

    char* error = "test";
    char** ppcText = &error;

    其中:

    const char *ppcText[1] = {"test"};

    然后代码应进行编译。

    上面的 ppcText 只有一个数组条目、您可以在运行时展开或更改 const char *指针以更改文本。