czwartek, 19 czerwca 2025

Loading text files - C++ Builder

 



pFile.h

#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.FileCtrl.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
TLabel *Label1;
TFileListBox *FileListBox1;
TDirectoryListBox *DirectoryListBox1;
TDriveComboBox *DriveComboBox1;
TMemo *Memo1;
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FileListBox1Change(TObject *Sender);
private: // User declarations
void __fastcall init_Components();
void __fastcall Run();
public: // User declarations
DWORD size_Bytes;
HANDLE ident;
char buff[1024+1024+1024+1024];
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

pFile.cpp

#include <vcl.h>
#pragma hdrstop

#include "pFile.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
SECURITY_ATTRIBUTES s_a;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
  s_a={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Run()
{
int i;
char c='.';
memset(buff,0,sizeof(buff)-1);
ident=CreateFile(FileListBox1->FileName.c_str(),GENERIC_READ, FILE_SHARE_READ,
&s_a,OPEN_EXISTING,0,NULL);
if(ident!=INVALID_HANDLE_VALUE)
ReadFile(ident,&buff,sizeof(buff),&size_Bytes,NULL);
for(i=0;i<sizeof(buff)-1;i++)
if(buff[i]==NULL)
  buff[i]=c;
Memo1->Text=buff;
CloseHandle(ident);

}
void __fastcall TForm1::init_Components()
{
DirectoryListBox1->FileList=FileListBox1;
DriveComboBox1->DirList=DirectoryListBox1;

}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 UnicodeString t,d;
 t=TimeToStr(Time());
 d=DateToStr(Date());
 Label1->Caption=t+"  "+d;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
 init_Components();
}





Brak komentarzy:

Prześlij komentarz