Jump to content

Drummer1972

Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. Hello. Using firemonkey 11. 1 c++ builder for android platform, I want that when a button is clicked, a function (void Loop()) is executed, in which two components are hidden (C1 and C2 visible=false), a cycle of 1,000,000 intervals, a ProgressBar (PB) componenet is executed in the THREAD while the loop is active; and this will be repeated until the loop ends or the Timage image (Imge1) is clicked. At the end of the loop, the progress bar will be hidden and components C1 and C2 will be displayed. I want to know if it is possible to control the progress bar in the thread and how to do it. I have tried it in the following way.: THREAD: ifndef ThreadUnitH #define ThreadUnitH #include <System.Classes.hpp> #include <FMX.Controls.hpp> class TProgressThread : public TThread { private: TProgressBar *ProgressBar; bool &StopFlag; protected: void __fastcall Execute(); public: __fastcall TProgressThread(TProgressBar *PB, bool &stopFlag); }; #endif //--------------------------------------------------------------------------- .CPP //--------------------------------------------------------------------------- #include <fmx.h> #include "PB.h" __fastcall TProgressThread::TProgressThread(TProgressBar *PB, bool &stopFlag) : TThread(true), ProgressBar(PB), StopFlag(stopFlag) { FreeOnTerminate = true; } void __fastcall TProgressThread::Execute() { while (!StopFlag) { TThread::Synchronize(nullptr, [this]() { if (ProgressBar->Value < ProgressBar->Max) ProgressBar->Value += 100; }); Sleep(10); } } FORM: .H //--------------------------------------------------------------------------- class TF : public TForm { __published: // IDE-managed Components TButton *Button1; TImage *Image1; TProgressBar *PB; TLabel *C1; TLabel *C2; TLabel *Label1; void __fastcall Button1Click(TObject *Sender); void __fastcall Image1Click(TObject *Sender); private: // User declarations bool StopThread; public: // User declarations void filtrar(); __fastcall TF(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TF *F; //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- .CPP //--------------------------------------------------------------------------- #include <fmx.h> #include <System.Threading.hpp> // Para usar TTask #pragma hdrstop #pragma hdrstop #include "Progress.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TF *F; TThread *workerThread = nullptr; //--------------------------------------------------------------------------- __fastcall TF::TF(TComponent* Owner) : TForm(Owner) { StopThread = false; } //--------------------------------------------------------------------------- void __fastcall TF::Button1Click(TObject *Sender) { C1->Visible = false; C2->Visible = false; PB->Visible = true; PB->Value = 0; PB->Max = 1000000; TProgressThread *Thread = new TProgressThread(PB, StopThread); Thread->Start(); Loop(); } void TF::Loop() { int i=0; for (i = 0; i < 1000000; i++) { if (StopThread) {Break;} Sleep(10); PB->Visible = false; TThread::Synchronize(nullptr, [this]() { C1->Visible = true; C2->Visible = true; }); } //--------------------------------------------------------------------------- void __fastcall TF::Image1Click(TObject *Sender) { StopThread = true; } Attached image for easy understanding Any ideas Thank you
  2. Drummer1972

    Doubts about THorzScrollBox operation

  3. Drummer1972

    Doubts about THorzScrollBox operation

    I have one THorzScrollBox with three TGridLayouts (c++ Builder 11): ¿Can I move it around with the mouse (ShowScrollBars=false)? Any ideas.. THANKS
  4. Drummer1972

    Pass working delphi code to c++ builder

    Thank you very much for answering.. I use rad studio 11. Volvo has given me the solution and it is the following: for ( int A = 0 ; A < HorzScrollBox1 - > Content - > ChildrenCount ; A ++ ) { static_cast < TGridLayout * > ( HorzScrollBox1 - > Content - > Children - > Items [ A ] ) - > Width = HorzScrollBox1 - > Width ; } dobleÚltimoPanel = 1.0 ; // <--- solo un ejemplo, ponga su valor aquí HorzScrollBox1 - > ViewportPosition = PointF ( LastPanel * HorzScrollBox1 - > Width, 0.0 ) ;
  5. Drummer1972

    Pass working delphi code to c++ builder

    Hello I work with C++ and I need to use this code written in Delphi (it works): Var A:Integer; Var LastPanel : Double; Begin For A:=0 to HorzScrollBox1.Content.ChildrenCount-1 do TGridLayout (HorzScrollBox1.Content.Children[A].widht:= HorzScrollBox1.width; HorzScrollBox1.ViewportPosition:=TPointF.Create(LastPanel * HorzScrollBox1.width,0 ); End; I have implemented only : for (int a=0; a<=HorzScrollBox1->Content->ChildrenCount-1;a++) { TGridLayout(HorzScrollBox1->Content->Children[a])->Width = HorzScrollBox1->Width} HorzscrollBox1->ViewportPosition= On the line : "TGridLayout(HorzScrollBox1->Content->…” it gives me the error : matching conversion for functional-style cast from 'Fmx::Types::TFmxChildrenList' to 'Fmx::Layouts::TGridLayout'" lso I think that TPointF is a type included in SystemTypes.h. It's possible?. THANKS
×