niedziela, 2 czerwca 2019

TFileStream and read a text file (class C++ Builder)


class read_text_File : public TFileStream
{
private:
unsigned long length_file;
UnicodeString filename;
int size_bytes;
BY_HANDLE_FILE_INFORMATION info;
TFileStream *file;
wchar_t *buf;
public:
read_text_File(const System::UnicodeString name, TListBox *lBox,
unsigned short temp_value):
TFileStream(name,temp_value)
{
buf=new wchar_t[1024];
filename=name;
file=new TFileStream(filename,fmOpenRead);
file->Read(buf,1024);
lBox->SetTextBuf(buf);
if(GetFileInformationByHandle((HANDLE)Handle,&info))
{
length_file=info.nFileSizeLow;
}
delete buf;
file->Free();


}
unsigned int Size()
{
return length_file;
}

};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 UnicodeString my_File="avaya.txt";
 read_text_File *OPEN=new read_text_File(my_File,ListBox1,1);
 Label1->Caption=OPEN->Size();
}

Brak komentarzy:

Prześlij komentarz