自定义函数中引用组件,对组件属性操作,提示组件未定义
初学BCB,在自定义函数中引用组件,对组件属性操作,提示组件未定义,这是为什么?组件是已经创建的,form create 事件中已经对其初始化了,我的自定义函数放在本窗体的.C文件中,这样不行吗?
#ifndef Unit1H
#define Unit1H
//---------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------
class TForm1 : public TForm
{
__published:// IDE-managed Components
TButton *Button1;
TMemo *mmo1;
void __fastcall Button1Click(TObject *Sender);
private:// User declarations
public:// User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------
#endif
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// 自定义函数,非类成员
void MyProcToSetMemoText(const char *txt)
{
Form1->mmo1->Text = txt;
// 顺便再设置下Form1->mmo1 的其他属性
Form1->mmo1->Color = clRed;
Form1->mmo1->Font->Color = clYellow;
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyProcToSetMemoText("卖家曝切尔西6300万签卡瓦尼 签5人狂烧1.8亿");
}
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------