sobota, 28 października 2017

File attributes (C++ Builder)



private:    // User declarations
    HANDLE idFile;
    TSearchRec tempSR;
    UnicodeString f,t;
    DWORD sizeB;
    wchar_t buffer_Memo[8192],s;
    void __fastcall connect_Components();


TForm1 *Form1;
SECURITY_ATTRIBUTES app_Attr={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::connect_Components()
{
    f="FALSE";
    t="TRUE";
    s='.';
    DirectoryListBox1->FileList=FileListBox1;
    DriveComboBox1->DirList=DirectoryListBox1;
    FileListBox1->FileEdit=Edit1;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 connect_Components();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
 int i;
 tempSR.Name=Edit1->Text;
 tempSR.Attr=FileGetAttr(tempSR.Name);
 if((tempSR.Attr && faArchive)==faArchive)
  Edit2->Text=t;
 else
  Edit2->Text=f;
 if((tempSR.Attr & faSysFile)==faSysFile)
  Edit3->Text=t;
 else
  Edit3->Text=f;
 if((tempSR.Attr & faReadOnly)==faReadOnly)
  Edit4->Text=t;
 else
  Edit4->Text=f;
 if((tempSR.Attr & faHidden)==faHidden)
  Edit5->Text=t;
 else
  Edit5->Text=f;
  memset(buffer_Memo,0,sizeof(buffer_Memo)-1);
  idFile=CreateFile(FileListBox1->FileName.c_str(),GENERIC_READ,FILE_SHARE_READ,
  &app_Attr,OPEN_EXISTING,0,NULL);
  if(idFile!=INVALID_HANDLE_VALUE)
   ReadFile(idFile,&buffer_Memo,sizeof(buffer_Memo),&sizeB,NULL);
  for(i=0;i<sizeof(buffer_Memo)-1;i++)
   if(buffer_Memo[i]==NULL)
    buffer_Memo[i]=s;
  Memo1->Text=buffer_Memo;
  CloseHandle(idFile);
}

Brak komentarzy:

Prześlij komentarz