[7146] Trailing whitespace code cleanup
[getmangos.git] / contrib / dbcEditer / dbcedit.cpp
blob2812a3f707114c901d81ae4e7e1959d249c5cc1f
1 //---------------------------------------------------------------------------
3 #include <vcl.h>
4 #pragma hdrstop
6 #include "dbcedit.h"
7 #include "stdio.h"
8 #include "IdGlobal.hpp"
9 #include <inifiles.hpp>
10 #include "TitleFrm.h"
11 #include <dir.h>
12 #include "thOpenSource.h"
13 #include "SearchFrm.h"
14 //#include "SysUtils.hpp"
17 //---------------------------------------------------------------------------
18 #pragma package(smart_init)
19 #pragma resource "*.dfm"
20 TFrmMain *FrmMain;
21 //---------------------------------------------------------------------------
22 __fastcall TFrmMain::TFrmMain(TComponent* Owner)
23 : TForm(Owner)
25 OpenOk=false;
26 Term=false;
28 //---------------------------------------------------------------------------
30 void __fastcall TFrmMain::btOpenClick(TObject *Sender)
32 if(OpenDialog1->Execute()){
33 if (FileExists(OpenDialog1->FileName)){
34 OpenOk=false;
35 if(thOpen){
36 thOpen->Terminate();
38 thOpen = new thOpenFile(false);
39 //thOpen->Priority = tpTimeCritical;
40 pnFileName->Caption = OpenDialog1->FileName;
41 }else{
42 OpenOk=false;
43 pnFileName->Caption = "";
47 //---------------------------------------------------------------------------
48 void __fastcall TFrmMain::btSaveClick(TObject *Sender)
50 //CurrentOpenFile;
51 if(OpenOk){
52 SaveToFile(CurrentOpenFile.c_str());
53 }else{
54 ShowMessage("Îļþδ´ò¿ªÍê³É£¡");
57 //---------------------------------------------------------------------------
59 void TFrmMain::SaveToFile(const char * pszFileName)
61 char szFileName[255];
62 FILE *stream;
67 fnsplit(pszFileName, 0, 0, szFileName, 0);
68 strcat(szFileName, "_new.dbc");
71 AnsiString NewFileName=ExtractFilePath(Application->ExeName)+szFileName;//=pszFileName;
72 int iFileHandle; //Îļþ¾ä±ú
73 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
74 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
76 DWORD w;
78 CopyFileTo(pszFileName,NewFileName);
80 iFileHandle = FileOpen(NewFileName, fmOpenRead|fmOpenWrite);//´ò¿ªÎļþ
82 if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
83 == NULL)
85 ShowMessage("´ò¿ªÎļþ³ö´í");
86 return;
90 int iVal;
91 float fVal;
92 bool isFloat;
93 int ColType;
95 FileSeek(iFileHandle,0x14,0);
96 TIniFile *ini;
97 ini = new TIniFile( iniSetFile );
99 for(int i=1; i<sgEdit->RowCount; i++)
101 for(int j=1; j<sgEdit->ColCount; j++)
103 if(j==1){ //ID
104 iVal=StrToInt(sgEdit->Cells[j][i]);
105 FileWrite(iFileHandle, &iVal, 4);
106 }else{
108 //ColType= ini->ReadInteger(SectionName,"ColType"+IntToStr(j-1),0);
109 //thOpen->ColType[10000];
111 switch (thOpen->ColType[j])
113 case 0: //ÕûÐÍ
114 iVal=StrToFloat(sgEdit->Cells[j][i]);
115 FileWrite(iFileHandle, &iVal, 4);
116 break;
117 case 1: //¸¡µã
118 fVal=StrToFloat(sgEdit->Cells[j][i]);
119 FileWrite(iFileHandle, &fVal, 4);
120 break;
121 case 2: //Îı¾
122 fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(j-1))*4, 0);
123 fread(&iVal, 4, 1, stream);
124 FileWrite(iFileHandle, &iVal, 4);
125 break;
126 default: //ÕûÐÍ
127 iVal=StrToFloat(sgEdit->Cells[j][i]);
128 FileWrite(iFileHandle, &iVal, 4);
133 FileClose(iFileHandle);
134 fclose(stream);
136 delete ini;
137 ShowMessage("Save To File:"+NewFileName);
139 void __fastcall TFrmMain::btIntTypeClick(TObject *Sender)
141 if(OpenOk==true){
142 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
143 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
144 TIniFile *ini;
145 ini = new TIniFile( iniSetFile );
146 ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),0);
147 delete ini;
148 thOpen->ColType[sgEdit->Col]=0;
149 //ÖØдò¿ª¶ÔÓ¦ÁеÄÖµ
150 //OpenFileCol(AnsiString FileName,int ColType);
151 OpenFileCol(CurrentOpenFile,sgEdit->Col,0);
154 //---------------------------------------------------------------------------
157 void __fastcall TFrmMain::btFloatTypeClick(TObject *Sender)
159 if(OpenOk==true){
160 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
161 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
162 TIniFile *ini;
163 ini = new TIniFile( iniSetFile );
164 ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),1);
165 delete ini;
166 thOpen->ColType[sgEdit->Col]=1;
167 OpenFileCol(CurrentOpenFile,sgEdit->Col,1);
170 //---------------------------------------------------------------------------
172 void __fastcall TFrmMain::PopupMenu1Popup(TObject *Sender)
174 if(OpenOk==true){
175 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
176 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
177 int ColType;
178 TIniFile *ini;
179 ini = new TIniFile( iniSetFile );
180 ColType=ini->ReadInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),0);
181 delete ini;
182 switch (ColType)
184 case 0:
185 btIntType->Checked=true;
186 btFloatType->Checked=false;
187 btTxtType->Checked=false;
188 break;
189 case 1:
190 btIntType->Checked=false;
191 btFloatType->Checked=true;
192 btTxtType->Checked=false;
193 break;
194 case 2:
195 btIntType->Checked=false;
196 btFloatType->Checked=false;
197 btTxtType->Checked=true;
198 break;
199 default:
200 btIntType->Checked=true;
201 btFloatType->Checked=false;
205 //---------------------------------------------------------------------------
207 void __fastcall TFrmMain::N1Click(TObject *Sender)
209 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
210 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
211 int ColType;
212 FrmTitle->edTitle->Text=sgEdit->Cells[sgEdit->Col][0];
213 if(FrmTitle->ShowModal()==mrOk){
214 TIniFile *ini;
215 ini = new TIniFile( iniSetFile );
216 ini->WriteString(SectionName,"ColTitle"+IntToStr(sgEdit->Col),FrmTitle->edTitle->Text);
217 delete ini;
218 sgEdit->Cells[sgEdit->Col][0]=FrmTitle->edTitle->Text;
221 //---------------------------------------------------------------------------
225 void __fastcall TFrmMain::FormDestroy(TObject *Sender)
227 if(thOpen){
228 thOpen->Terminate();
229 SleepEx(200,0);
232 //---------------------------------------------------------------------------
234 void __fastcall TFrmMain::ToolButton1Click(TObject *Sender)
236 bool SeFlag=true;
237 if(FrmSearch->ShowModal()==mrOk){
238 switch (FrmSearch->rgSI->ItemIndex)
240 case 0: //ÏòÉÏÕÒ;
241 for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col-1;i>sgEdit->ColCount;i--){
242 if(i%sgEdit->ColCount!=0){
243 if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount],
244 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
245 sgEdit->Col=i-sgEdit->ColCount*i/sgEdit->ColCount;
246 sgEdit->Row=i/sgEdit->ColCount;
247 SeFlag=false;
248 break;
252 if(SeFlag) ShowMessage("Seach Top£¬Find Nothing.");
253 break;
254 case 1: //ÏòÏÂÕÒ;
255 for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col+1;i<sgEdit->ColCount*sgEdit->RowCount;i++){
256 if(i%sgEdit->ColCount!=0){
257 if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount],
258 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
259 sgEdit->Col=i-sgEdit->ColCount*(i/sgEdit->ColCount);
260 sgEdit->Row=i/sgEdit->ColCount;
261 SeFlag=false;
262 break;
266 if(SeFlag) ShowMessage("Seach End£¬Find Nothing");
267 break;
268 case 2: //µ±Ç°ÁÐÏòÉÏÕÒ;
269 for(int i=sgEdit->Row;i>1;i--){
270 if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i],
271 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
272 sgEdit->Row=i;
273 SeFlag=false;
274 break;
277 if(SeFlag) ShowMessage("Seach col top£¬Find Nothing");
278 break;
279 case 3: //µ±Ç°ÁÐÏòÏÂÕÒ;
280 for(int i=sgEdit->Row;i<sgEdit->RowCount;i++){
281 if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i],
282 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
283 sgEdit->Row=i;
284 SeFlag=false;
285 break;
288 if(SeFlag) ShowMessage("Seach col end£¬Find Nothing.");
289 break;
293 //---------------------------------------------------------------------------
295 void __fastcall TFrmMain::sgEditKeyDown(TObject *Sender, WORD &Key,
296 TShiftState Shift)
299 bool SeFlag=true;
300 if(Key==VK_F3){
301 switch (FrmSearch->rgSI->ItemIndex)
303 case 0: //ÏòÉÏÕÒ;
304 for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col-1;i>sgEdit->ColCount;i--){
305 if(i%sgEdit->ColCount!=0){
306 if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount],
307 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
308 sgEdit->Col=i-sgEdit->ColCount*i/sgEdit->ColCount;
309 sgEdit->Row=i/sgEdit->ColCount;
310 SeFlag=false;
311 break;
315 if(SeFlag) ShowMessage("Seach Top£¬Find Nothing.");
316 break;
317 case 1: //ÏòÏÂÕÒ;
318 for(int i=sgEdit->ColCount*sgEdit->Row+sgEdit->Col+1;i<sgEdit->ColCount*sgEdit->RowCount;i++){
319 if(i%sgEdit->ColCount!=0){
320 if( 0==CompareStr(sgEdit->Cells[i-sgEdit->ColCount*(i/sgEdit->ColCount)][i/sgEdit->ColCount],
321 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
322 sgEdit->Col=i-sgEdit->ColCount*(i/sgEdit->ColCount);
323 sgEdit->Row=i/sgEdit->ColCount;
324 SeFlag=false;
325 break;
329 if(SeFlag) ShowMessage("Seach End£¬Find Nothing.");
330 break;
331 case 2: //µ±Ç°ÁÐÏòÉÏÕÒ;
332 for(int i=sgEdit->Row;i>1;i--){
333 if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i],
334 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
335 sgEdit->Row=i;
336 SeFlag=false;
337 break;
340 if(SeFlag) ShowMessage("Seach col Top£¬Find Nothing.");
341 break;
342 case 3: //µ±Ç°ÁÐÏòÏÂÕÒ;
343 for(int i=sgEdit->Row;i<sgEdit->RowCount;i++){
344 if( 0==CompareStr(sgEdit->Cells[sgEdit->Col][i],
345 FrmSearch->edSeach->Text)){ //ÕÒµ½ÁË
346 sgEdit->Row=i;
347 SeFlag=false;
348 break;
351 if(SeFlag) ShowMessage("Seach col end£¬Find Nothing.");
352 break;
356 //---------------------------------------------------------------------------
358 void __fastcall TFrmMain::sgEditSelectCell(TObject *Sender, int ACol,
359 int ARow, bool &CanSelect)
363 //---------------------------------------------------------------------------
364 void __fastcall TFrmMain::OpenFileCol(AnsiString FileName,int ColIndex,int ColType)
366 int iFileHandle; //Îļþ¾ä±ú
367 char Txtbuf[255];
368 int iVal;
369 float fVal;
370 FILE *stream;
371 long curpos, length;
372 DWORD dwRows, dwCols, dwRowLen, dwTextLen;
374 DWORD dwTextStartPos;
375 char* pTextPtr ;
378 if ((stream = fopen(FileName.c_str(), "r+"))
379 == NULL)
381 ShowMessage("Open File Error");
382 return;
385 curpos = ftell(stream);
386 fseek(stream, 0L, SEEK_END);
387 length = ftell(stream);
390 switch (ColType)
392 case 0: //ÕûÐÍÖµ Int
393 for(int i=0;i<sgEdit->RowCount-1;i++){
394 fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
395 fread(&iVal, 4, 1, stream);
396 sgEdit->Cells[ColIndex][i+1]=IntToStr(iVal);
398 break;
399 case 1: //¸¡µãÖµ Float
400 for(int i=0;i<sgEdit->RowCount-1;i++){
401 fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
402 fread(&fVal, 4, 1, stream);
403 sgEdit->Cells[ColIndex][i+1]=FloatToStr(fVal);
405 break;
406 case 2: //Îı¾ Text
407 fseek(stream,0x4,0);
408 fread(&iVal, 4, 1, stream);
409 dwRows= iVal;
410 fread(&iVal, 4, 1, stream);
411 dwCols = iVal;
412 fread(&iVal, 4, 1, stream);
413 dwRowLen = iVal;
414 fread(&iVal, 4, 1, stream);
415 dwTextLen = iVal;
417 dwTextStartPos = dwRows*dwRowLen+20;
418 for(int i=0;i<sgEdit->RowCount-1;i++){
419 fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
420 fread(&iVal, 4, 1, stream);
421 sgEdit->Cells[ColIndex][i+1]=IntToStr(iVal);
422 if(dwTextStartPos + iVal < length){
423 fseek(stream,dwTextStartPos + iVal,0);
424 fread(Txtbuf, 1, 255, stream);
425 //pTextPtr = pBuff + dwTextStartPos + lTemp;
426 sgEdit->Cells[ColIndex][i+1]=Txtbuf;
427 }else{
428 sgEdit->Cells[ColIndex][i+1]="This Col Not Text!";
431 break;
433 fclose(stream);
435 void __fastcall TFrmMain::Timer1Timer(TObject *Sender)
437 if(OpenOk){
438 lbOpState->Caption = "Open File Ok.";
439 }else{
440 lbOpState->Caption = "Open Now.....";
443 //---------------------------------------------------------------------------
444 //µ±Ç°¸ñ×ÓдÈëÐÞ¸ÄÎļþÖÐ
445 void __fastcall TFrmMain::N4Click(TObject *Sender)
447 if(!thOpen) return;
449 int iFileHandle; //Îļþ¾ä±ú
450 char buf[4];
451 int iVal;
452 float fVal;
453 FILE *stream;
455 if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
456 == NULL)
458 ShowMessage("´ò¿ªÎļþ³ö´í");
459 return;
462 iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//´ò¿ªÎļþ
464 switch (thOpen->ColType[sgEdit->Col])
466 case 0: //ÕûÐÍÖµ
467 //for(int i=0;i<sgEdit->RowCount-1;i++){
469 fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
470 iVal=StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
471 memcpy(buf, &iVal, 4);
472 for(int i=0;i<4;i++)
473 fwrite(buf+i, 1, 1, stream);
475 iVal=StrToInt(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
476 memcpy(buf, &iVal, 4);
477 FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0);
478 FileWrite(iFileHandle,buf,4);
480 break;
481 case 1: //¸¡µãÖµ
482 //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
483 //fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
484 //fwrite(&fVal, 4, 1, stream);
485 fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][sgEdit->Row]);
486 memcpy(buf, &fVal, 4);
487 FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0);
488 FileWrite(iFileHandle,buf,4);
489 break;
490 case 2: //Îı¾²»Ð´Èë
491 break;
494 // fclose(stream);
495 FileClose(iFileHandle);
497 //---------------------------------------------------------------------------
499 void __fastcall TFrmMain::btTxtTypeClick(TObject *Sender)
501 if(OpenOk==true){
502 AnsiString iniSetFile=ExtractFilePath(Application->ExeName)+"BcdEditer.ini";
503 AnsiString SectionName=ExtractFileName(CurrentOpenFile);
504 TIniFile *ini;
505 ini = new TIniFile( iniSetFile );
506 ini->WriteInteger(SectionName,"ColType"+IntToStr(sgEdit->Col),2);
507 delete ini;
508 thOpen->ColType[sgEdit->Col]=2;
509 OpenFileCol(CurrentOpenFile,sgEdit->Col,2);
512 //---------------------------------------------------------------------------
514 void __fastcall TFrmMain::ToolButton3Click(TObject *Sender)
516 int OldCol;
517 int OldRow;
518 OldRow=sgEdit->Row;
519 OldCol=sgEdit->Col;
520 if(sgEdit->FixedCols==1){
521 sgEdit->FixedCols =2;
522 if(OldCol!=1)
523 sgEdit->Col=OldCol;
524 sgEdit->Row=OldRow;
525 }else{
526 sgEdit->FixedCols =1;
527 sgEdit->Row=OldRow;
528 if(OldCol!=2)
529 sgEdit->Col=OldCol;
532 //---------------------------------------------------------------------------
534 void __fastcall TFrmMain::btRowSaveClick(TObject *Sender)
536 if(OpenOk==false) return;
538 int iFileHandle; //Îļþ¾ä±ú
539 char Txtbuf[255];
540 int iVal;
541 char buf[4];
542 float fVal;
543 FILE *stream;
544 long curpos, length;
545 DWORD dwRows, dwCols, dwRowLen, dwTextLen;
547 DWORD dwTextStartPos;
548 char* pTextPtr ;
551 //if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
552 // == NULL)
554 // ShowMessage("´ò¿ªÎļþ³ö´í");
555 // return;
558 //curpos = ftell(stream);
559 //fseek(stream, 0L, SEEK_END);
560 //length = ftell(stream);
561 iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//´ò¿ªÎļþ
563 for(int i=0;i<sgEdit->ColCount-1;i++){
564 switch (thOpen->ColType[i])
566 case 0: //ÕûÐÍÖµ sgEdit->Row
567 //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
568 //iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
569 //fwrite(&iVal, 4, 1, stream);
570 iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
571 memcpy(buf, &iVal, 4);
572 FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4,0);
573 FileWrite(iFileHandle,buf,4);
574 break;
575 case 1: //¸¡µãÖµ
576 //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
577 //fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
578 //fwrite(&fVal, 4, 1, stream);
579 fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
580 memcpy(buf, &fVal, 4);
581 FileSeek(iFileHandle,0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4,0);
582 FileWrite(iFileHandle,buf,4);
583 break;
584 case 2: //Îı¾ ²»´æ
585 break;
588 //fclose(stream);
589 FileClose(iFileHandle);
590 ShowMessage("The "+IntToStr(sgEdit->Row)+" Row Write Ok!");
592 //---------------------------------------------------------------------------
594 void __fastcall TFrmMain::btColSaveClick(TObject *Sender)
596 if(OpenOk==false) return;
598 int iFileHandle; //Îļþ¾ä±ú
599 char Txtbuf[255];
600 int iVal;
601 char buf[4];
602 float fVal;
603 FILE *stream;
604 long curpos, length;
605 DWORD dwRows, dwCols, dwRowLen, dwTextLen;
607 DWORD dwTextStartPos;
608 char* pTextPtr ;
610 iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead|fmOpenWrite);//´ò¿ªÎļþ
612 //if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
613 // == NULL)
615 // ShowMessage("´ò¿ªÎļþ³ö´í");
616 // return;
619 //curpos = ftell(stream);
620 //fseek(stream, 0L, SEEK_END);
621 //length = ftell(stream);
624 switch (thOpen->ColType[sgEdit->Col])
626 case 0: //ÕûÐÍÖµ
627 for(int i=0;i<sgEdit->RowCount-1;i++){
628 //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
629 //iVal=StrToInt(sgEdit->Cells[sgEdit->Col][i+1]);
630 //fwrite(&iVal, 4, 1, stream);
631 iVal=StrToInt(sgEdit->Cells[sgEdit->Col][i+1]);
632 memcpy(buf, &iVal, 4);
633 FileSeek(iFileHandle,0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0);
634 FileWrite(iFileHandle,buf,4);
636 break;
637 case 1: //¸¡µãÖµ
638 for(int i=0;i<sgEdit->RowCount-1;i++){
639 //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4, 0);
640 //fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][i+1]);
641 //fwrite(&fVal, 4, 1, stream);
642 fVal=StrToFloat(sgEdit->Cells[sgEdit->Col][i+1]);
643 memcpy(buf, &fVal, 4);
644 FileSeek(iFileHandle,0x14+(i*(sgEdit->ColCount-1)+(sgEdit->Col-1))*4,0);
645 FileWrite(iFileHandle,buf,4);
647 break;
648 case 2: //Îı¾ ²»´æ
649 break;
651 //fclose(stream);
653 FileClose(iFileHandle);
654 ShowMessage("The "+IntToStr(sgEdit->Col)+"Col Write Ok!");
656 //---------------------------------------------------------------------------
658 void __fastcall TFrmMain::btRowClearClick(TObject *Sender)
660 if(OpenOk==false) return;
662 int iFileHandle; //Îļþ¾ä±ú
663 char Txtbuf[255];
664 int iVal;
665 float fVal;
666 FILE *stream;
667 long curpos, length;
668 DWORD dwRows, dwCols, dwRowLen, dwTextLen;
670 DWORD dwTextStartPos;
671 char* pTextPtr ;
674 if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
675 == NULL)
677 ShowMessage("Open File Error!");
678 return;
681 curpos = ftell(stream);
682 fseek(stream, 0L, SEEK_END);
683 length = ftell(stream);
685 for(int i=1;i<sgEdit->ColCount-1;i++){
686 switch (thOpen->ColType[i])
688 case 0: //ÕûÐÍÖµ sgEdit->Row
689 //fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0);
690 //iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
691 //fwrite(&iVal, 4, 1, stream);
692 sgEdit->Cells[i+1][sgEdit->Row]="0";
693 break;
694 case 1: //¸¡µãÖµ
695 //fseek(stream, 0x14+(sgEdit->Row*(sgEdit->ColCount-1)+i)*4, 0);
696 //fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
697 //fwrite(&fVal, 4, 1, stream);
698 sgEdit->Cells[i+1][sgEdit->Row]="0";
699 break;
700 case 2: //Îı¾ ²»´æ
701 break;
704 fclose(stream);
706 //---------------------------------------------------------------------------
708 void __fastcall TFrmMain::btColClearClick(TObject *Sender)
710 if(OpenOk==false) return;
712 int iFileHandle; //Îļþ¾ä±ú
713 char Txtbuf[255];
714 int iVal;
715 float fVal;
716 FILE *stream;
717 long curpos, length;
718 DWORD dwRows, dwCols, dwRowLen, dwTextLen;
720 DWORD dwTextStartPos;
721 char* pTextPtr ;
724 if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
725 == NULL)
727 ShowMessage("Open File Error!");
728 return;
731 curpos = ftell(stream);
732 fseek(stream, 0L, SEEK_END);
733 length = ftell(stream);
736 switch (thOpen->ColType[sgEdit->Col])
738 case 0: //ÕûÐÍÖµ
739 for(int i=0;i<sgEdit->RowCount-1;i++){
740 //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
741 //iVal=StrToInt(sgEdit->Cells[ColIndex][i+1]);
742 //fwrite(&iVal, 4, 1, stream);
743 sgEdit->Cells[sgEdit->Col][i+1]="0";
745 break;
746 case 1: //¸¡µãÖµ
747 for(int i=0;i<sgEdit->RowCount-1;i++){
748 //fseek(stream, 0x14+(i*(sgEdit->ColCount-1)+(ColIndex-1))*4, 0);
749 //fVal=StrToFloat(sgEdit->Cells[ColIndex][i+1]);
750 //fwrite(&fVal, 4, 1, stream);
751 sgEdit->Cells[sgEdit->Col][i+1]="0";
753 break;
754 case 2: //Îı¾ ²»´æ
755 break;
757 fclose(stream);
759 //---------------------------------------------------------------------------
761 void __fastcall TFrmMain::ToolButton4Click(TObject *Sender)
763 AnsiString Cmd;
764 Cmd = "calc.exe";
765 WinExec(Cmd.c_str(), SW_SHOWNORMAL);
767 //---------------------------------------------------------------------------