niedziela, 20 lipca 2025

My class info_File - C++ Builder

 




 m_File.h

#ifndef m_FileH
#define m_FileH
//---------------------------------------------------------------------------
class info_File
{
 private:

 UnicodeString Name;
 UnicodeString Size;
 UnicodeString Modification;
 UnicodeString Attribute;
public:
 TFileListBox *TL;
 TListBox *TB;
 TSearchRec t_Rec;
 TStrings* i_File;
 info_File(TFileListBox *a1, TListBox *b1);
 void Load();
 void Run();
 ~info_File();

};
#endif

m_File.cpp


#pragma hdrstop
#include <vcl.h>
#include <Vcl.FileCtrl.hpp>
#include <Vcl.StdCtrls.hpp>
#include <System.Classes.hpp>
#include "m_File.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
info_File::info_File(TFileListBox *a1, TListBox *b1)
{
UnicodeString temp;
TL=a1;
TB=b1;
temp=TL->FileName;
if(FindFirst(temp,faAnyFile,t_Rec)!=0)
{
return;
}
FindClose(t_Rec);
i_File=new TStringList();


}
void info_File::Load()
{
   Name=(UnicodeString)t_Rec.Name;
   Size=(UnicodeString)t_Rec.Size;
   Modification=(UnicodeString)DateTimeToStr(FileDateToDateTime(t_Rec.Time));
   Attribute=IntToStr(t_Rec.Attr);
   i_File->Add("Name: "+ Name);
   i_File->Add("Size: "+Size);
   i_File->Add("Date last modification: "+Modification);
   i_File->Add("Attribute: "+Attribute);


}
void info_File::Run()
{
   TB->Items->Clear();
   TB->Items->Assign(i_File);


}
info_File::~info_File()
{
    delete i_File;
}



Project: Unit1.cpp

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "m_File.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 DirectoryListBox1->FileList=FileListBox1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FileListBox1Click(TObject *Sender)
{
 info_File Date(FileListBox1,ListBox1);
 Date.Load();
 Date.Run();
}



sobota, 12 lipca 2025

std::sort() - C++ Builder


#include <vcl.h>
#include <algorithm>
#include <random>
#include <vector>

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 Button1->Caption="&RUN";
 Button2->Caption="&CLOSE";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j,k;
 struct Point
 {
int x;
int y;
 };
 std::vector<Point> date;
 std::random_device r1;
 std::mt19937 gen(r1());
 std::uniform_int_distribution<>dist(1,25);
 for(i=0;i<5;i++)
 {
date.push_back({dist(gen),dist(gen)});
 }
 j=0;
 for(const auto& temp1 : date)
 {
StringGrid1->Cells[j][0]=IntToStr(temp1.x);
StringGrid1->Cells[j][1]=IntToStr(temp1.y);
++j;
 }
 std::sort(begin(date),end(date),[] (const Point &v1, const Point &v2)
 {
return v1.y<v2.y;
 });
 j=0;
 for(const auto& temp2 : date)
 {
StringGrid2->Cells[j][0]=IntToStr(temp2.x);
StringGrid2->Cells[j][1]=IntToStr(temp2.y);
++j;
 }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 Close();
}