Garmaine Staff asked 1 year ago

I need to add the variables T1, T2 so that they are read in LABELEDIT and summed up BUTTON1CLICK, but I can’t figure out how to format it correctly, as you can see I made them only with a record from the code.

it seems easy but i dull out of the blue

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

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

void MyTime::show()
{
    AnsiString s;
    s = IntToStr(chas) + ":" + IntToStr(min) + ":" + IntToStr(sec);
    Form1->Memo1->Lines->Add(s);
}

void MyTime::summa(MyTime t1, MyTime t2)
{
    sec = t1.sec + t2.sec;
    min = t1.min + t2.min;
    chas = t1.chas + t2.chas;
    if (sec >= 60) {
        min++;
        sec -= 60;
    }
    if (min >= 60) {
        chas++;
        min -= 60;
    }
    if (chas >= 24)
        chas = chas - 24;
}

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}

void __fastcall TForm1::Button1Click(TObject* Sender)
{
    Memo1->Clear();
    MyTime T1(13, 23, 50), T2(10, 52, 50), T3;
    T1.show();
    T2.show();
    T3.summa(T1, T2);
    T3.show();
}

unit.h

#ifndef Unit1_mytimeH
#define Unit1_mytimeH

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>

class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TMemo *Memo1;
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:    // User declarations
public:        // User declarations
    __fastcall TForm1(TComponent* Owner);
};

   class MyTime {
   private:
    int chas;
    int min;
    int sec;
 public:
    MyTime() { chas=0; min=0; sec=0; }
    MyTime(int ch, int m, int s) {
       chas=ch; min=m; sec=s;
    }
    void show();
    void summa(MyTime t1, MyTime t2);
};

extern PACKAGE TForm1 *Form1;
#endif