Category: Firemonkey

threads and ttask delphi fmx?

i am trying to do some processing on second thread and for that i am currently using TTask and currently coded this thing with the knowledge i gained from previous explained questions here and in other tutorials : procedure Process; var Task: ITask; sMS, pMS, pMS2: TMemoryStream; Bitmap1, Bitmap2, Bitmap3: TBitmap; sRect: TRect; begin Form2.AniIndicator1.Visible := true; Task := TTask.Create( procedure begin sPdf := TDebenuPDFLibrary1613.Create; sPdf.UnlockKey('stackoverflow@1234'); if sPdf.LoadFromFile(FileName, 'RAMBO@45454593') = 1 then begin sPdf.SetOrigin(1); sPdf.SelectRenderer(4); sPdf.SetPDFiumFileName('eLibUM32.dll'); pMS := TMemoryStream.Create; pMS2 := TMemoryStream.Create; try sPdf.SetPageBox(2, 37, 659, 243, 152); sPdf.RenderPageToStream(300, 0, 5, pMS); Bitmap1 := TBitmap.CreateFromStream(pMS); sPdf.SetPageBox(2, 314, 659, 243, 152); sPdf.RenderPageToStream(300, 0, 5, pMS2); Bitmap2 := TBitmap.CreateFromStream(pMS2); with sRect do begin Top := 0; Left := 0; Width := Bitmap1.Width; Height := Bitmap1.Height; end; Bitmap3:= TBitmap.Create; with Bitmap3 do begin Height := Bitmap1.Height; Width := Bitmap1.Width * 2 + 5; Clear(TAlphaColors.White); CopyFromBitmap(Bitmap1, sRect, 0, 0); CopyFromBitmap(Bitmap2, sRect, sRect.Width + 5, 0); end; TThread.Queue(TTHread.CurrentThread, procedure begin Form2.AniIndicator1.Visible := False; Form2.Image1.Bitmap.Assign(Bitmap3); end); finally pMS.Free; pMS2.Free; end; end else TThread.Queue(TThread.CurrentThread, procedure begin ShowMessage('Password Error !'); end); sPdf.Free; end); Task.Start; end; but sometimes it does not loads the bitmap into image1 of form2. am i doing any mistakes in task or in que of thread ?
Read More

Delphi IDE, FM form designer, Windows key produces a left square bracket

When I have a FireMonkey project loaded with a form design surface focused pressing the windows key produces a left square bracket into whatever property has focus. Often this produces an "Invalid property value." error and reverts the unwanted change but not always. Does not happen with VCL forms or data modules. No luck tracking down where it is coming from. Anybody else see this behavior or know where it is coming from? I use CTRL + Windows Key + Left/Right Arrow to switch desktops a lot and this behavior is getting annoying.
Read More

Cursor handling in Firemonkey

Can anyone clarify how cursors in Delphi FMX 10.3.1 work? I have a lengthy action and I want the application's cursor to be displayed as crHourglass while the action is executing. In the following code I have introduced 3 options for setting the cursor to crHourglass. procedure TFormMain.ActionFindExactMatchesExecute(Sender: TObject); const CCursorOption= 2; var IterationContextHits: TIterationContextHits; begin PanelResults.SendToBack; PanelProgress.BringToFront; case CCursorOption of 0: Self.Cursor:= crHourglass; 1: ButtonFindExactMatches.Cursor:= crHourglass; 2: CursorManager.SetCursor(crHourglass); end; {Create TIterationContextHits object to hold progress variables:} IterationContextHits:= TIterationContextHits.Create; try {Lengthy code that searches multiple files for string matches} {Report result of operation:} ShowMessage('Number of matches found: ' + IntToStr(FHitCount)); {Update GUI:} DataToControls; PanelResults.BringToFront; finally IterationContextHits.Free; case CCursorOption of 0: Self.Cursor:= crDefault; 1: ButtonFindExactMatches.Cursor:= crDefault; 2: CursorManager.RestorePrevCursor; end; end; end; In the first option, I set the Cursor property of the MainForm to crHourGlass in the expectation that during execution the application will display the InheritedCursor property, which should search the component z-order stack all the way back to the main form for the first component whose cursor value is not crDefault. But this does not work. In the second option I set the cursor property of a button that is linked to the action. If the button is clicked to launch the action, the cursor change works. But if the action is launched from a main menu item, then it doesn't. In the third option I use an object of class TCursorManager that I have written to wrap the platform-dependent service IFMXCursorService. This mostly works, but not invariably. The code for this is: TCursorRecord= record FCursor: TCursor; FStartTime: integer; end; TCursorRecordArray= array of TCursorRecord; TCursorManager= class private FCursorService: IFMXCursorService; FCursorRecordStack: TCursorRecordArray; FCursorRecordCount: integer; protected function GetCursorTickCount: integer; public constructor Create; destructor Destroy; override; function GetCursor: TCursor; {Returns currently set cursor} procedure SetCursor(Cursor: TCursor); {Sets new cursor} function RestorePrevCursor: TCursor; {Restores cursor previously set using this object} property Cursor: TCursor read GetCursor write SetCursor; property CursorTickCount: integer read GetCursorTickCount; end; implementation constructor TCursorManager.Create; var CurrCursorRecord: TCursorRecord; begin {Create platform-dependent cursor service:} if TPlatformServices.Current.SupportsPlatformService(IFMXCursorService) then FCursorService:= TPlatformServices.Current.GetPlatformService(IFMXCursorService) as IFMXCursorService; {Create current cursor record:} CurrCursorRecord.FCursor:= FCursorService.GetCursor; CurrCursorRecord.FStartTime:= GetTickCount; {Put current cursor record onto CursorRecordStack:} SetLength(FCursorRecordStack, 8); FCursorRecordCount:= 1; FCursorRecordStack[0]:= CurrCursorRecord; end; function TCursorManager.RestorePrevCursor: TCursor; var PrevCursorRecord: TCursorRecord; begin if Assigned(FCursorService) then begin if FCursorRecordCount>0 then begin {Remove current cursor record from stack:} FCursorRecordCount:= FCursorRecordCount - 1; PrevCursorRecord:= FCursorRecordStack[FCursorRecordCount-1]; {Reduce size of stack array if possible:} if FCursorRecordCount mod 8 = 0 then SetLength(FCursorRecordStack, FCursorRecordCount); {Update start time of new curr cursor:} PrevCursorRecord.FStartTime:= GetTickCount; {Set previous cursor in system:} FCursorService.SetCursor(PrevCursorRecord.FCursor); {Return prev cursor:} Result:= PrevCursorRecord.FCursor; end; end; end; procedure TCursorManager.SetCursor(Cursor: TCursor); var NewCursorRecord: TCursorRecord; begin if Assigned(FCursorService) then begin {Set up new CursorRecord:} NewCursorRecord.FCursor:= Cursor; NewCursorRecord.FStartTime:= GetTickCount; {Add new cursor record to stack:} if FCursorRecordCount= Length(FCursorRecordStack) then SetLength(FCursorRecordStack, FCursorRecordCount + 8); Inc(FCursorRecordCount); FCursorRecordStack[FCursorRecordCount-1]:= NewCursorRecord; {Call system procedure to set cursor:} FCursorService.SetCursor(Cursor); end; end; What is the simplest way to achieve what I am seeking to accomplish?
Read More

Android and Application.ProcessMessages

i have application where I'm using form as message box, in this "message box" i run thread that changing messages on it and after thread finish, on message box i show buttons, only after clicking on button code can continue var FStart: TFStart; VariableX:Boolean; implementation uses UApp,UMess; {$R *.fmx} procedure TFStart.Button2Click(Sender: TObject); begin VariableX:=false; { There i show window and start thread after finish thread set VariableX as true and close form } // There i need to wait until thread finish while VariableX = false do Application.ProcessMessages; { there i will continue to work with data returned by thread } end; I know that Marco Cantu say that its not good idea to use Application.ProcessMessages In my case application stop with sigterm (On windows and ios its working good) How to do it without Application.ProcessMessages?
Read More

Changing the background color behind a selected substring in a Firemonkey TMemo component

I wish to programmatically set focus on a particular substring in a (Delphi 10.3.1) Firemonkey TMemo component, by painting a yellow background behind the substring. The code below paints a yellow rectangle in the right position, but the rectangle appears to be superimposed over the text, thereby hiding it. Is there some TMemo property that can be used to avoid this? If not, what is the recommended fix? procedure TTextGUIMemo.SetFocusOnHit(HitIndex: integer); var LineIndex: integer; GlobalHitInterval: TIntegerArray2; begin FFileCptHitsExpd.FileCptHits.GetHitSubstringGlobal(HitIndex, {=>}LineIndex, GlobalHitInterval); FMemo.SetFocus; FMemo.SelStart:= GlobalHitInterval[0]; FMemo.SelLength:= GlobalHitInterval[1]; FMemo.SelectionFill.Color := TAlphaColorRec.Yellow; FMemo.FontColor:= TAlphaColorRec.Black; FMemo.Repaint; end; Thank you in advance for any suggestions.
Read More

WinHTTP Open method is causing delay?

I am using WinHTTP 5.1 in one of my Delphi FMX application which connects to REST servers in parallel. There are lot of GET and POST which are called continuously by the client. I have observed that after say 200-300 GET commands below method is becoming extremely slow: WinHTTPRequest.Open(FURL, FDocument, True) The credentials are set properly and i can observe on Wireshark that the Open method is taking approx a minute to execute as after open i am calling Send : WinHTTPRequest.Send Any advises ?
Read More

Android Widget in Delphi 10.3

I would like to create a widget for android using Delphi 10.3 and Firemonkey. I didn't find any valuable information about it except a little old task: (RAD XE5 Studio and Android widget) Can anyone suggest how to make such a widget? Has something changed since the XE version to 10.3 that can help in the preparation of such a widget?
Read More

FireMonkey Beta for ImageEn, Imaging Library

We have now released a beta version of ImageEn/FireMonkey. At this time, only Windows targets are supported. Other platforms are planned.

It is a direct port of our VCL version, but does NOT include:

Any Dialogs
– ImageEn open/save dialogs
– Built-in image effects dialog (TImageEnProc.DoPreviews)
– Built-in image I/O properties dialog (TImageEnIO.DoPreviews)
– Layer Properties dialog
– Printing and Print Preview dialogs

Any Windows Features
– Windows shell components and features (such as video thumbnails)
– TIEFolderMView
– WIC file formats and features
– GDI+
– Rich formatting for text layers
– AVI and Meta-File support

– Image Acquisition (Twain, WIA, WPD)
– Video Acquisition (DirectShow, MMF)
– Support for plug-ins like ImageMagick and WpViewPDF
– Legacy components: TImageEnVect, THSVBox and TGradientBox

Naturally being a beta, it will have bugs and incompatibilities. Beta testers are expected to test and report issues.

The beta is open to anyone with an active ImageEn license (as it includes all ImageEn source code). For more information, visit:

Sample Compiled Demos

Complete Editor:
Image display and editing application

Thumbnail Viewer:
Using TImageEnMView to show thumbnails for images in a folder

All Layer Editing:
Usage of image, shape, text and line layers

Image Editor Actions Demo:
Complete image display and editing application built using only the TImageEnView Action set

Layer Actions Demo:
Complete image layer editing application built using only the TImageEnView Action set

Thumbnail Actions Demo:
Multiple image display and editing application built using only the TImageEnMView Action set

All Actions Demo:
Demo showing all ImageEn actions (230+) available to rapidly build applications

Brush Tool Demo:
Using the in-built Brush tool to paint onto an image

Clone Tool Demo:
Using the in-built Clone Brush tool to copy and erase content within an image

Flood Fill Tool:
Using the Fill tool to replace the color within an image with a new color or transparency

Transition Effects:
Use of transition effects to smooth the changing of images during a slideshow

Photosphere Viewer:
Interactive display of “Equirectangular” images (Google Android PhotoSphere 360° panoramic images)

Zoom Filter Comparison:
Display of all the available ZoomFilter effects for image smoothing

Magic Fill to Polygon:
Creates a polygon by performing a magic selection on an image (matching a color range)

Navigator Demo:
Use of TImageEnView.SetNavigator to show the currently viewable portion of the image

Cells and Grid Demo:
Divide an image into a grid and allow selection of individual cells More

Read More

Firemonkey styles – duplicate a certain style lookup to customize

In a Firemonkey project, I have a TListBox with numerous items. Depending on the state of any given item, I intend to show the Detail as either red or white (on a black background). Of course I need to use the styles to do this. I right-click one of the TListBoxItem controls and choose "Edit Custom Style...". It's my understanding that it's supposed to produce a new copy of whatever the current style lookup is just for this one control. In my case, I had already set it to listboxitemrightdetail prior to trying to customize it. What I would expect is that when I make a change to the font color in this style and "Apply and Close", that one single list box item should get that change. However, instead of that one, ALL of the items in this list box got that change. The change I made actually modified the listboxitemrightdetail rather than producing a copy of it just for that one control. In the end, I intend to have two style lookups, for example listboxitemreddetail and listboxitemwhitedetail which I can toggle on each list item in runtime. What am I doing wrong, and what's the appropriate way to duplicate a style lookup to have two different versions?
Read More

Firemonkey ListView scrollbar visibility

In the Firemonkey's TListview the visibility of the scroll bar depends whether the system has a touch screen. How can I override this behavior and show vertical scrolling always when there is not enough room on the list view to display all list items? I saw within TListViewBase.Create that the scroll visibility depends again on the function result of HasTouchTracking and this depends if TScrollingBehaviour.TouchTracking is set in SystemInformationService.GetScrollingBehaviour. Does anyone have a glue how I can override this behavior?
Read More