回 帖 发 新 帖 刷新版面

主题:新手學習,請高手指點,clock

不久前在網上(此BLOG上也有,標題是<<C++Builder制作闹钟>>看到一個鬧鐘功能的代碼,按上面的指導作了以下代碼,但始終不能運行,代碼如下,最下面有錯誤報警,my pc sys w2K,bcb ver.6.0,初學,請高手不憐指點迷經.
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::t_ClockTimer(TObject *Sender)
{
//按時触發演示程序
struct date d;
struct time t;
AnsiString thour,tmin,tsec;
int dyear;
int dintyear;
int dmon,dday;
AnsiString tinthour,tintmin,tintsec;
AnsiString dintmon,dintday;
//取當天日期
getdate(&d);
dyear=d.da_year;
dday=d.da_day;
dmon=d.da_mon;
dintyear=StrToInt(dint.SubString(1,2));
dintmon=dint.SubString(4,2);
dintday=dint.SubString(7,2);
//取當天時間
gettime(&t);
thour=AnsiString(t.ti_hour);
tmin=AnsiString(t.ti_min);
//tsec=AnsiString(t.ti_sec);
//tint=AnsiString(DateTimePicker1- >Time);
tinthour=tint.SubString(10,2);
tintmin=tint.SubString(13,2);
//tintsec=tint.SubString(16,2);
//鬧鐘服務功能
if ((StrToInt(thour)==StrToInt(tinthour))&&
(StrToInt(tmin)==StrToInt(tintmin))
&&(StrToInt(AnsiString(dyear).SubString(3,2))
==dintyear)&&(StrToInt(dmon)==StrToInt(dintmon))
&&(StrToInt(dday)==StrToInt(dintday)))
{
dTimer- >Enabled=false;
MediaPlayer1->Open();
MediaPlayer1->Play();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::b_Clock_OpenClick(TObject *Sender)
{
t_Clock->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::b_Clock_CloseClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------

[C++ Error] Unit1.cpp(23): E2450 Undefined structure 'date'
[C++ Error] Unit1.cpp(23): E2449 Size of 'd' is unknown or zero
[C++ Error] Unit1.cpp(23): E2450 Undefined structure 'date'
[C++ Error] Unit1.cpp(24): E2450 Undefined structure 'time'
[C++ Error] Unit1.cpp(24): E2449 Size of 't' is unknown or zero
[C++ Error] Unit1.cpp(24): E2450 Undefined structure 'time'
[C++ Error] Unit1.cpp(32): E2268 Call to undefined function 'getdate'
[C++ Error] Unit1.cpp(33): E2315 'da_year' is not a member of 'date', because the type is not yet defined
[C++ Error] Unit1.cpp(34): E2315 'da_day' is not a member of 'date', because the type is not yet defined
[C++ Error] Unit1.cpp(35): E2315 'da_mon' is not a member of 'date', because the type is not yet defined
[C++ Error] Unit1.cpp(36): E2451 Undefined symbol 'dint'
[C++ Error] Unit1.cpp(40): E2268 Call to undefined function 'gettime'
[C++ Error] Unit1.cpp(41): E2315 'ti_hour' is not a member of 'time', because the type is not yet defined
[C++ Error] Unit1.cpp(42): E2315 'ti_min' is not a member of 'time', because the type is not yet defined
[C++ Error] Unit1.cpp(45): E2451 Undefined symbol 'tint'
[C++ Error] Unit1.cpp(55): E2451 Undefined symbol 'dTimer'
[C++ Error] Unit1.cpp(55): E2188 Expression syntax
[C++ Error] Unit1.cpp(56): E2451 Undefined symbol 'MediaPlayer1'

回复列表 (共3个回复)

沙发

找不到结构定义。 "Unit1.h"没加到工程吧。

板凳

再问,如何添加?

3 楼

新开一个工程,把代码复制到这个工程中即可

我来回复

您尚未登录,请登录后再回复。点此登录或注册