各位工程師大大們好 小弟是初入行的軟體工程師 最近在寫 StringGrid載入txt中資料的程式
但發現若載入的資料過多,或反覆的載入資料 會出現 :
Access violation at address 32665A01 in module 'CC3260MT.DLL'. Read of address F87ADB14
的訊息 想請問各位大大這是什麼函意呢? 可以建議我要如何解求呢? 謝謝!
以下是我的程式碼:
=====================================================================================
//---------------------------------------------------------------------------
#include
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
char Buf[500];
char *FileName;
char *ModelNo;
char *EquipmentNo;
char *BinGrade;
char *WaferID1;
char *Qty1;
char *TChip;
char *Rvlw;
char *Rvlw1;
char seps[]=":,.csv";
char seps1[]="Avg,";
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
StringGrid2->Left=-108-ScrollBar1->Position;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DriveComboBox1Change(TObject *Sender)
{
DriveComboBox1->DirList=DirectoryListBox1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)
{
DirectoryListBox1->FileList=FileListBox1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int m;
for ( m = 0; m < FileListBox1->Items->Count; m )
{
}
for (int x=0;x<11;x ) //清除StringGrid2的內容
for (int y=0;y<200;y )
{
StringGrid1->Cells[x][y] ="";
StringGrid2->Cells[x][y] ="";
StringGrid3->Cells[x][y] ="";
}
for(int k=0;k{
String path;
int i;
FileListBox1->ItemIndex =k;
path=FileListBox1->FileName;
Panel1->Visible=false;
FILE *ptr;
char buf[100];
sprintf(buf,"%s",path.c_str()); //以String 宣告path的字容無結束字元,故丟到字串變數buf中
ptr=fopen(buf,"rt"); //以便讓ptr載入內容時有截止點
fgets(Buf,200,ptr);//1
FileName = strtok(Buf,seps);
i=k 1;
while(FileName !=NULL)
{
FileName=strtok(NULL,seps);
StringGrid1->Cells[0][i]=FileName;
i ;
}
fgets(Buf,200,ptr);//2
ModelNo=strtok(Buf,seps);
i=k 1;
while(ModelNo !=NULL)
{
ModelNo=strtok(NULL,seps);
StringGrid1->Cells[1][i]=ModelNo;
i ;
}
fgets(Buf,200,ptr);//3
fgets(Buf,200,ptr);//4
fgets(Buf,200,ptr);//5
fgets(Buf,200,ptr);//6
EquipmentNo=strtok(Buf,seps);
i=k 1;
while(EquipmentNo !=NULL)
{
EquipmentNo=strtok(NULL,seps);
StringGrid1->Cells[2][i]=EquipmentNo;
i ;
}
fgets(Buf,200,ptr);//7
fgets(Buf,200,ptr);//8
BinGrade=strtok(Buf,seps);
i=k 1;
while(BinGrade !=NULL)
{
BinGrade=strtok(NULL,seps);
StringGrid1->Cells[3][i]=BinGrade;
i ;
}
fgets(Buf,200,ptr);//9
fgets(Buf,200,ptr);//10
fgets(Buf,200,ptr);//11
fgets(Buf,200,ptr);//12
WaferID1=strtok(Buf,seps);
int j=1;
j=(k*2) j;
StringGrid2->Cells[1][j]=WaferID1;
i=2;
while(WaferID1 !=NULL)
{
WaferID1=strtok(NULL,seps);
StringGrid2->Cells[i][j]=WaferID1;
i ;
}
fgets(Buf,200,ptr);//13
fgets(Buf,200,ptr);//14
Qty1=strtok(Buf,seps);
j=(k*2) 2;
i=2;
StringGrid2->Cells[1][j]=Qty1;
while(Qty1 !=NULL)
{
if (i>10)
{
j=(k*2) j 2;
i=1;
}
Qty1=strtok(NULL,seps);
StringGrid2->Cells[i][j]=Qty1;
i ;
}
fgets(Buf,200,ptr);//15
TChip=strtok(Buf,seps);
i=k 1;
while(TChip !=NULL)
{
TChip=strtok(NULL,seps);
StringGrid1->Cells[4][i]=TChip;
i ;
}
fgets(Buf,200,ptr);//16
fgets(Buf,200,ptr);//17
fgets(Buf,200,ptr);//18
fgets(Buf,200,ptr);//19
fgets(Buf,200,ptr);//20
Rvlw1=strtok(Buf,seps1);
j=k 1;
StringGrid3->Cells[0][j]=Rvlw1;
i=1;
while(Rvlw1 !=NULL)
{
Rvlw1=strtok(NULL,seps1);
StringGrid3->Cells[i][j]=Rvlw1;
i ;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button13Click(TObject *Sender)
{
Panel1->Visible=true;
}
//---------------------------------------------------------------------------