• PUDN用户
    了解作者
  • C++ Builder
    开发工具
  • 297KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 59
    下载次数
  • 2006-07-12 04:47
    上传日期
BCB文件打开操作示例,并有转换成Hex格式显示功能
FileWriteRead.rar
  • FileWriteRead
  • Unit1.dfm
    912B
  • Unit1.cpp
    2.1KB
  • WriteRead.bpr
    2.6KB
  • Unit1.h
    1.1KB
  • WriteRead.exe
    471KB
  • Unit1.obj
    19.4KB
  • WriteRead.obj
    9.2KB
  • WriteRead.res
    876B
  • WriteRead.cpp
    664B
  • WriteRead.tds
    704KB
  • www.pudn.com.txt
    218B
内容介绍
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include "stdio.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int iFileHandle; int iFileLength; int iBytesRead; char *pszBuffer; AnsiString hexBuffer=""; char hexchar[4]; if (OpenDialog1->Execute()) { Memo1->Clear(); Memo2->Clear(); iFileHandle = FileOpen(OpenDialog1->FileName, fmOpenRead); iFileLength = FileSeek(iFileHandle,0,2); FileSeek(iFileHandle,0,0); pszBuffer = new char[iFileLength+1]; iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength); FileClose(iFileHandle); Memo1->Lines->LoadFromFile(OpenDialog1->FileName); for (int i=0;i<iBytesRead;i++) { sprintf(hexchar,"%02x ",int(pszBuffer[i])); hexBuffer+=AnsiString(hexchar).UpperCase(); } Memo2->Lines->Add(hexBuffer); delete [] pszBuffer; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { int iFileHandle; int iLength; if (SaveDialog1->Execute()) { if (FileExists(SaveDialog1->FileName)) { RenameFile(SaveDialog1->FileName,SaveDialog1->FileName+".BAK"); } iFileHandle = FileCreate(SaveDialog1->FileName); for (int i=0;i<Memo2->Lines->Count;i++) { iLength = Memo2->Lines->Strings[i].Length(); FileWrite(iFileHandle, Memo2->Lines->Strings[i].c_str(), iLength); } FileClose(iFileHandle); } } //---------------------------------------------------------------------------
评论
    相关推荐