Jump to content

bravesofts

Members
  • Content Count

    37
  • Joined

  • Last visited

Community Reputation

2 Neutral

Recent Profile Visitors

1289 profile views
  1. sorry @Remy Lebeau no i didn't at that way !! --- i ask both question at the same time !! --- and with Your big and huge respect of your knowledge, I'm done learning that Method: [ITask.ExecuteWork] from ITask is: runs the task in the calling thread ... ---- again please: Forgive my ignorance and stupidity !! i was just there to ask and not because this site or other didn't help !! --- finally . i thank you all for your replys and especially for taking from your time.. i love you all & respect you all .. @Dalija Prasnikar regardless of others... i respect you a lot .
  2. also i learn that the Method ExecuteWork: [ is used to run the task in the calling thread => in my case the main App thread ] like inject or run a safe thread inside the MainThreadAPP and this exactly what i looking for.... --- so my question here: Why Method ExecuteWork Fail in mobile device (especially ANDROID) ? ----- is this have problem with Android OS ?? ----- Please don't tell me that Method : ExecuteWork is not a regular or illegal or what ever else ... otherwhise why the EMB Group add it inside the interface ITASK ? ---- what i know in language programming : the interface is safer and destinated at-least to users like me .... --- with best Respects & Regards ...
  3. sorry again ... --- last question: is it impossible to create threads in mobile devices while avoiding the main app thread from going to the next line of code until tasks complete ? for example this code here didn't work in android devices: begin _Taskcomplete := false; try fTask := TTask.Create( procedure begin // Here you do your task code while not _Taskcomplete do Lbl_Task.Text := ElapsedSec.ToString; TThread.Synchronize(nil, procedure begin // Here you can call code that needs to run after task is finished Lbl_Task.Text := 'task complete ..'; end); end); fTask.Start; finally while not _Taskcomplete do Application.ProcessMessage; // in Android the APP freeze !! showMessage('we wait until Task Complete to show you this message !!'); end; end; from what i learn above is i can only use wait function to run the SoCalled "After Task Complete Procedures or functions" inside the task thread using synchronize method..!!
  4. Not block the main thread in that definition... !!! I think the stupid sleep function is the unsafe way to block main thread... ---- I mean block main thread using the safe way like executeWork does... ---- I'm afread again : Delphi does not support background threads in Android and iOS devices where the main thread wait smoothly and safe...
  5. Is there a safe solution to block the main thread smoothly without freezing the app while waiting our task to complete "using the right task way above.. " Especially in mobile devices
  6. About my repository didn't help you understand my request... --- I simply if I Don't use itask.ExecuteWork; and use the regular Start; The main thread App will not wait for task completion and execute the next line code... But with executeWork I succeeded to force main thread App to wait smoothly without freezing the app.... I don't like use sleep function inside while loop in order to execute background thread... --- Try to use my wrong code (like I said before it's not complete...) in VCL and FMX windows example and you will find the magic of executeWork method.. --- NB: sorry for my wrong solution in my GIthub..
  7. In android maybe android service could help... Or add some Java activities that play our background threads safely while our main thread App is using while loop application.processmessage;
  8. Unfortunately didn't help at all... I see that post before..
  9. Is there any solution targeting the mobile devices!! ---- I'm afraid that : Delphi does not support background threads in Android and iOS devices !! ---- And if yes... I think it's OS problem or Firemonkey single Main Activity doesn't accept more activities !!!
  10. This is my git repository uses that method executeWork: Wait Solution Here Maybe help to understand my request.. Nb: my repo not complete yet... Wait Solution (VCL/FMX) Stop the Use of Stupid Sleep function !! Now with this Solution : your Main thread Should Wait until your wait function finsh her work without freezing the entire App using the stupid Sleep function !!! other Threads that are runing outside your MainThread (they still could work without Any Problem!!) using the method ExecuteWork from ITask we can force the App to wait until Our WaitThread finish work
  11. i have this code here: fTask: ITask; fTask := TTask.Create( procedure begin while not True do Application.ProcessMessages; TThread.Synchronize(TThread.Current, procedure begin // update ui end); end); fTask.ExecuteWork; // this will stop here.. until [fTask] finish work !! In android didn't wait untill Task Complete !!
  12. honestly i'm a native Delphi !!! ------- my post here is to understand exactly what delphi is that i was used before without a deep attention to delphi details
  13. and what about the exe it's self ? does A variable having a type equal to a class is actually a pointer to the memory allocated for the class instance inside the exe it's self and not comming from calling the constructor. !!! i mean the delphi is deployed for us a ready to use objects variables that pointer to the exe it's self (pre Allocated Classes)
  14. First : i have this code: type TClass_Instance = class(TClass_Ancestor) end; what happen at runtime when our program is using this Unit? i mean exactly this Explicit : TClass_Instance = class(TClass_Ancestor) does this Allocate something in Memory ? or system resources .... second: ihave this declaration here: var vObj_Instance: TClass_Instance; begin end; what happen at runtime when we are declaring some Objects ? i mean exactly this Declaration : vObj_Instance: TClass_Instance; does this Allocate something in Memory ? or system resources .... third: i have this code here: type {$M+} TBaseForm = class(TForm) // This my template Base Form procedure Abstracted_Event(Sender: TObject); virtual; abstract; end; TSubBase_1 = class(TBaseForm) // SubBase_1 Members goes here .. published procedure Abstracted_Event(Sender: TObject); Override; end; TSubBase_2 = class(TBaseForm) // SubBase_2 Members goes here .. published procedure Abstracted_Event(Sender: TObject); Override; end; TSubBase_3 = class(TBaseForm) // SubBase_3 Members goes here .. published procedure Abstracted_Event(Sender: TObject); Override; end; i have this super procedure for calling sub forms acording to their Class Names: procedure Get_SubForm(AFormClass: TFormClass; aOwner: TComponent; aParent: TWinControl); var vObjInstance: TBaseForm; // Define Object Instance Type; vRef: TBaseForm; // our Object vRef is the Universal variable for All SubForms that inherited from TBaseForm begin vObjInstance := TBaseForm(AFormClass.NewInstance); //Fill Object [vObjInstance] with [AFormClass.NewInstance] .. vRef := vObjInstance.Create(aOwner); //Fill Object [vRef] with [vObjInstance.Create] .. try vRef.Parent := aParent; vRef.Align := alClient; vRef.BorderStyle := bsNone; vRef.OnShow := vRef.Abstracted_Event; finally vRef.Show; end; end; my question is : what happen here: vObjInstance := TBaseForm(AFormClass.NewInstance); //Fill Object [vObjInstance] with [AFormClass.NewInstance] .. at runtime ...? does this line Above is trying to replace the first declaration Above here: var vObjInstance: TBaseForm; // Define Object Instance Type; in other words: does NewInstance Above is trying to redeclare our variable vObjInstance with Another Type ? if not (so what happen exactlly ?) Another sample Example: procedure TFrmMain.Btn_CreateObjClick(Sender: TObject); var vObj_Instance: TButton; // declaration Type of our Object vRef: TButton; begin vObj_Instance := TButton(TButton.NewInstance); vRef := vObj_Instance.Create(Self); try vRef.Parent := Self; vRef.Name := 'Btn_vObj'+ ComponentCount.ToString; vRef.SetBounds(Round(8 * fScaleFactor), Round(48 * fScaleFactor), Round(185 * fScaleFactor), Round(41 * fScaleFactor)); finally vRef.Visible := True; end; end; here i'm using the same approach Above that using TBaseForm but with one base Class TButton my question is: we used to use this Rule here: <vObject> := <ClassName>.<ConstructorName> ; but here we have an object trying to Allocate the memory (fiil the Class inside that variable) for Another Object ... my Remark: procedure TFrmMain.Btn_CreateObjClick(Sender: TObject); var // vObj_Instance: TButton; vRef: TButton; begin // vObj_Instance := TButton(TButton.NewInstance); vRef := Btn_CreateObj.Create(Self); try vRef.Parent := Self; vRef.Name := 'Btn_vObj'+ ComponentCount.ToString; vRef.SetBounds(Round(8 * fScaleFactor), Round(48 * fScaleFactor), Round(185 * fScaleFactor), Round(41 * fScaleFactor)); finally vRef.Visible := True; end; end; if we click on button Btn_CreateObj the object will be created but the Button Btn_CreateObj will be disappear !!! and when closing the app will have a memory leaks !!! my Approach of using another variable as a mediator, remind me with A & B replacement values var A, B, C: integer; begin A := 10; B := 5; // Solving requiring us Another Variable with the same Type C := A; A := B; B := C; // AND IT'S DONE .. end; finally: what is a Class Instance and an Object Instance? and is my Approach for creating base forms is a good approach or not ? thanks in Advance...
×