【问题标题】:How to give acess to the components of the fmx to a function in firemonkey C++?如何让 fmx 的组件访问 firemonkey C++ 中的函数?
【发布时间】:2021-06-25 18:52:03
【问题描述】:

我基本上想改变一个组件的状态,为此,我正在做这样的事情

void desenharpilha2(TImage *b1, TImage *b2, TImage *b3,TImage *b4, TImage *b5)
{
        b1->Visible = False;
        b2->Visible = False;
        b3->Visible = False;
        b4->Visible = False;
        b5->Visible = False;
}

基本上,将我需要更改的所有组件传递给函数,但我确信有更好的方法。

简而言之,我需要一种方法让函数能够访问 FMX 的所有组件,而不必传递我要更改的所有对象,因为如果我需要更改例如 15 个对象,则代码会一团糟。

【问题讨论】:

    标签: c++ firemonkey


    【解决方案1】:

    使desenharpilha2() 成为拥有您感兴趣的控件的 FMX Form 类的成员,例如:

    class TMyForm : public TForm
    {
    __published:
        TImage *b1;
        TImage *b2;
        TImage *b3;
        TImage *b4;
        TImage *b5;
        ...
    public:
        ...
        void desenharpilha2();
    };
    
    ...
    
    void TMyForm::desenharpilha2()
    {
        b1->Visible = False;
        b2->Visible = False;
        b3->Visible = False;
        b4->Visible = False;
        b5->Visible = False;
    }
    

    然后您可以在需要时在运行时调用所需的 Form 对象上的desenharpilha2(),例如:

    TMyForm *someForm = ...;
    ...
    someForm->desenharpilha2();
    

    【讨论】:

      猜你喜欢
      • 2022-01-27
      • 1970-01-01
      • 2017-05-29
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-22
      • 2015-10-02
      相关资源
      最近更新 更多