嗨我不知道如何调用函数在无形或非形式单位返回值。从无形或非形式单位的函数返回值
Unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button2;
TLabel *Label2;
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
USHORT lengthOfYard;
USHORT widthOfYard;
USHORT areaOfYard;
widthOfYard = 15;
lengthOfYard = 17;
areaOfYard= FindArea(lengthOfYard,widthOfYard);
Label2->Caption = "\nYour yard is "+ areaOfYard +" square feet\n\n";
}
//---------------------------------------------------------------------------
Unit3.h
//---------------------------------------------------------------------------
#ifndef Unit3H
#define Unit3H
//---------------------------------------------------------------------------
// declare the function here in the header file.
USHORT FindArea(USHORT length, USHORT width); //function prototype
#endif//---------------------------------------------------------------------------
Unit3.cpp
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
USHORT FindArea(USHORT l, USHORT w)
{
return l * w;
}
我无法找到此问题的解决方案或教程。 你有更好的吗? Clement
目前的文件组织看起来很好。你有任何警告/错误信息?你关心什么? – manlio
在Unit1.cpp中,错误是“Unit1.cpp(29):parsing:void _fastcall TForm1 :: Button2Click(TObject *)”突出显示错误“Label2-> Caption =”\ n您的代码是“+ areaOfYard +”square脚\ n \ n “;”。编译时发生错误。 – user1739825