czwartek, 14 września 2023

My class - save_Text - C++ Builder

 class save_Text

{

private:

char** buff;

int l_size;

    char* name;

ofstream my_File;

UnicodeString* date;

const int length=256;

public:

save_Text(char* file_Name,UnicodeString* text,int lines);

void Save();

~save_Text();


};

save_Text::save_Text(char* file_Name,UnicodeString* text,int lines)

{

 l_size=lines;

 name=file_Name;

 date=text;

 buff=new char*[l_size];

 for(int i=0;i<l_size;i++)

  buff[i]=new char[length];

}

void save_Text::Save()

{

 my_File.open(name);

 for(int i=0;i<l_size;i++)

 {

wcstombs(buff[i],date[i].w_str(),length);

my_File<<buff[i]<<"\n";

 }

 my_File.close();

}

save_Text::~save_Text()

{

for(int i=0;i<l_size;i++)

delete [] buff[i];

    delete []buff;

}

void __fastcall TForm1::Button3Click(TObject *Sender)
{
 UnicodeString safety_Tips[5];
 safety_Tips[0]="Report to Safety Cordinator";
 safety_Tips[1]="Stricty obey Safety Rules";
 safety_Tips[2]="Smoke only in designated areas";
 safety_Tips[3]="Keep Emergency Number near you";
 safety_Tips[4]="Do not take risks";

 save_Text Safety("safety.txt",safety_Tips,5);
 Safety.Save();

}

poniedziałek, 11 września 2023

Type Variant examples - C++ Builder

 


void __fastcall TForm1::FormCreate(TObject *Sender)
{
 Variant x;
 TVarData(x).VDate=Now();
 x=TVarData(x).VDate;
 Label1->Caption=VarToStr(x);
 int i,j;
 Variant integer_Tab(OPENARRAY(int,(1,10,1,10)),varInteger);
 Variant double_Tab(OPENARRAY(int,(1,10,1,10)),varDouble);
 Variant currency_Tab(OPENARRAY(int,(1,10,1,10)),varCurrency);
 Variant date_Tab(OPENARRAY(int,(1,10,1,10)),varDate);
 double k=0.01;
 for(i=0;i<10;i++)
 {
for(j=0;j<10;j++)
{
integer_Tab.PutElement((i+1)*(j+1),i+1,j+1);
double_Tab.PutElement(k*(i+1*1.00)*(j+1*1.00),i+1,j+1);
currency_Tab.PutElement(k*(i+1*1.00)+(j+1*1.00),i+1,j+1);
         date_Tab.PutElement(x,i+1,j+1);

}
 }
 for(i=0;i<10;i++)
 {
for(j=0;j<10;j++)
{
StringGrid1->Cells[i][j]=integer_Tab.GetElement(i+1,j+1);
StringGrid2->Cells[i][j]=double_Tab.GetElement(i+1,j+1);
StringGrid3->Cells[i][j]=currency_Tab.GetElement(i+1,j+1);
         StringGrid4->Cells[i][j]=date_Tab.GetElement(i+1,j+1);

}
 }

}