嗨我不知道如何調用函數在無形或非形式單位返回值。從無形或非形式單位的函數返回值
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