在更新檢查中,假如Excel A7中的欄位持續更動,程式即會發生錯誤,不知道是我的Timer設定錯誤還是程式的錯誤... 附上我的source code,希望前輩給予一些指點,謝謝~~ //--------------------------------------------------------------------------- #include
#include
#pragma hdrstop #include #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Excel_2K_SRVR"
#pragma resource "*.dfm"
TForm1 *Form1; int is_odd; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Exit_Click(TObject *Sender)
{ Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Open_Excel_Click(TObject *Sender)
{
WideString aa; if (OpenDialog1->Execute())
{
aa=OpenDialog1->FileName; ExcelApplication1->Connect();
ExcelApplication1->Workbooks->Open(aa); ExcelWorkbook1->ConnectTo(ExcelApplication1->get_ActiveWorkbook()); ExcelApplication1->set_Visible(0,true);
ExcelWorksheet1->ConnectTo(ExcelWorkbook1->get_ActiveSheet());
} delete aa ; } //---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{ Edit1->Text="";
Edit2->Text="";
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Exec_Click(TObject *Sender)
{ Timer1->Interval=8000;
is_odd=1;
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(is_odd == 1 )
{ int l,h,r1,r2,r3; Variant v1_7(7),v1_8(8),v1_9(9);
Variant v1(1);
Variant vr1,vr2,vr3; r1=StrToInt(VarToStr(vr1=ExcelWorksheet1->Cells->get__Default(v1_7,v1)));
//r2=StrToInt(VarToStr(vr2=ExcelWorksheet1->Cells->get__Default(v1_8,v1)));
//r3=StrToInt(VarToStr(vr3=ExcelWorksheet1->Cells->get__Default(v1_9,v1))); h=StrToInt(Edit1->Text);
l=StrToInt(Edit2->Text); if (r1l)
{
return ;
} else
{
OleContainer1->DoVerb(0);
} } }