[Android]TFrame create and delete

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

ingalime
Top Poster
Top Poster
Posts: 29
Joined: Wed Apr 12, 2017 3:22 am

Re: [Android]TFrame create and delete

Post by ingalime »

Hi, rlebeau!
I began to collect the fragments of your code for my white paper.
Please check again.
C++ Builder Berlin Up2:

Code: Select all

//h TFrame
//***
public:		// User declarations
	__fastcall TFrame1(TComponent* Owner);
    TNotifyEvent OnButtonClick;

Code: Select all

//cpp TFrame
TFrame1 *Frame1;
//---------------------------------------------------------------------------
__fastcall TFrame1::TFrame1(TComponent* Owner)
	: TFrame(Owner)
{

}
//---------------------------------------------------------------------------
void __fastcall TFrame1::Button1Click(TObject *Sender)
{
 //close frame
 if (OnButtonClick)
   OnButtonClick(this);
}

Code: Select all

//h main
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
	void __fastcall FrameButtonClicked(TObject *Sender);

Code: Select all

//main Form cpp
void __fastcall TForm1::FrameButtonClicked(TObject *Sender)
{
	Frame1->Release();
	Frame1 = nullptr;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 	Frame1 = new TFrame1(this);
	Frame1->Parent = this;
	Frame1->Label1->Text = L"Hello frame";
	Frame1->OnButtonClick = &FrameButtonClicked;
}

C++ Builder Tokyo 10.2.2:

Code: Select all

void __fastcall TForm1::FrameButtonClicked(TObject *Sender)
{
  TThread::ForceQueue(nullptr, [Frame1](){ Frame1->DisposeOf(); });
  Frame1 = nullptr;
}
And we cau use Frame in event ThreadTerminated. For example:

Code: Select all

 void __fastcall TFrame2::ThreadTerminated(TObject *Sender)
{

	Button2->Enabled = true;
	AniIndicator1->Visible = false;

	//close Frame2 with Memo1
	Frame2->Release();
	Frame2 = nullptr;

       //show Frame1 with message
	TMyConnect *Thread = static_cast<TMyConnect*>(Sender);
	if(Thread->FatalException)
	 {
	          Frame1 = new TFrame1(Form1);
		  Frame1->Parent = Form1;
		  Frame1->Label1->Text = L"Sorry, communication error with the server.";
		  Frame1->OnButtonClick = &(Form1->FrameButtonClicked); 
	 }
	else
	   {
		Frame1 = new TFrame1(Form1);
		Frame1->Parent = Form1;
		Frame1->Label1->Text = L"Thank you. All successfully";
		Frame1->OnButtonClick = &(Form1->FrameButtonClicked);
		Form1->Button2Click(0);//<--for example clear ListVew on main form
	   }

}
Is everything correct now?
Thank you.
Post Reply