|
---------------------------
Debugger Exception Notification
---------------------------
Project DT_EMS.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
동작은 잘하는데 종료시가 문제입니다.
메인폼에서 스트링그리드 달랑 있는 그리드폼을 쇼모달로 띄우고나서
프로그램 종료시 위와 같은 에러메세지를 랜덤하게(?) 띄웁니다~
급하게 짜느라 부잡스럽운 코드입니다만.. 무엇이 잘못되었을까요?
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "TGrid.h"
#include "TMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TGridForm *GridForm;
//---------------------------------------------------------------------------
__fastcall TGridForm::TGridForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TGridForm::FormShow(TObject *Sender)
{
SG->RowCount = 2;
Download();
}
//---------------------------------------------------------------------------
void __fastcall TGridForm::Download(void)
{
unsigned char buff[BUFFER_SIZE]; //buffer size [16]
int start, end, size, cnt = 0;
TFileStream* fs = new TFileStream(MainForm->Edit_Path->Text, fmOpenRead);
start = MainForm->ListView1->Items->Item[MainForm->ListView1->ItemIndex]->Caption.ToInt()+256; //256 header size
fs->Seek(start, soFromBeginning);
if(MainForm->ListView1->Items->Count-1 == MainForm->ListView1->ItemIndex)
end = fs->Size;
else
end = MainForm->ListView1->Items->Item[MainForm->ListView1->ItemIndex+1]->Caption.ToInt();
while(true) {
size = fs->Read(buff, BUFFER_SIZE);
start += size;
if(size == 0) break;
cnt++;
SG->Cells[0][SG->RowCount-1] = IntToStr(cnt); //cnt
SG->Cells[1][SG->RowCount-1] = IntToStr(buff[0]); //speed
SG->Cells[2][SG->RowCount-1] = IntToStr((buff[2]<<8)+buff[1]); //rpm
SG->Cells[3][SG->RowCount-1] = IntToStr(buff[3]); //aux
SG->Cells[4][SG->RowCount-1] = IntToStr((buff[5]<<8)+buff[4]); //
SG->Cells[5][SG->RowCount-1] = IntToStr((buff[9]<<24)+(buff[8]<<16)+(buff[7]<<8)+buff[6]); //
SG->Cells[6][SG->RowCount-1] = IntToStr((buff[13]<<24)+(buff[12]<<16)+(buff[11]<<8)+buff[10]); //
SG->Cells[7][SG->RowCount-1] = IntToStr((buff[15]<<8)+buff[14]); //
if(start >= end) break;
SG->RowCount++;
}
delete fs;
}
//---------------------------------------------------------------------------
|