Conversion to firemonkey - delphi

what becomes of of the
TStatusBar.Simpletext
property while converting a program from VCL to firmonkey ?

Add a TLabel on top of the TStatusBar, set the Align property to alClient. Set the label text property, and there you are.
Fmx components tries to reuse as much as possible from other basic components.
Unfortunately, the help documentation is not very informative.
Study the FMX.ControlsDemo_Sample.

Related

How can I set Touch Target Expansion on TRectangle in Delphi FireMonkey

I'm using TRectangle's for buttons on an FMX app, unfortunately, there's no property setting for TouchTargetExpansion like there's in most styled-components.
What is the way to get it on basic components such as TRectangle?
Another option that I used a lot is to add a TRectangle with fill color null over text and controls. Then you control the click area using this invisible rectangle. That way you can forget about the Touchtargetexpansion option and use this "invisible touch rectangle" on any area or component.

What is the ideal way to modify sub control styles in a custom firemonkey control?

I am attempting to develop my first proper custom control for the Firemonkey framework and have ran into what may possibly be an obvious (or not) solution.
Inside my Firemonkey control I have declared FPanel: TPanel; which is then created in the constructor and freed in the destructor. The panel is created along with my control when I add it to a new Multi-Device Form without any problems.
By default the TPanel has borders around the sides of the control which I do not need in my control.
So my question is, what is the ideal way to remove the borders of a TPanel which is child to my custom control? I could not see an obvious property to change, unless I am mistaking I believe we must modify the style of the panel which I assume would be done via a TStyleBook.
Am I right then in thinking that I need to add a TStyleBook to my control, and from there add the panel to the Style book and modify it this way? Unless I am missing something this seems like a lot of extra work for what should be a very quick and simple change.
Assuming this is the correct way, is there an example of modifying a TStyleBook through code?
Thanks.
Because all Firemonkey controls can be parents, one way is to not use TPanel at all and instead replace it with another Firemonkey control such as the TRectangle shape.
The TRectangle shape can then be customised directly through its properties to remove the border which can be achieved by setting the Corners and Sides to False.
Additionally if you don't require any borders whatsoever then the TLayout control behaves just like a TPanel but without the borders.

What are there advantages to using Static Text instead of Label in Delphi?

From the docwiki for labels:
You place a label on a form when you need to identify or annotate another component such as an edit box or when you want to include text on a form. The standard label component, TLabel, is a non-windowed control, so it cannot receive focus; when you need a label with a window handle, use TStaticText instead.
What does the statement "when you need a label with a window handle, use TStaticText instead" mean?
At work, we use a TStaticText when we want our UI automation testing tool to 'read' the text of a "label". Most of the interaction is done by Windows API messaging, so a TStaticText will respond to GetWindowText, while a TLabel will not. This is a simplistic overview on how we use TStaticText and a TLabel.
Also, if you're creating forms that need to work with screen readers for visually impaired users, TLabels can't be seen by the software, but TStaticText labels can.
Cut and pasted from Embarcadero
The TStaticText component functions like TLabel, except that it
descends from TWinControl and therefore has a window handle. Use
TStaticText instead of TLabel when the component's accelerator key
must belong to a windowed control—for example, on an ActiveX property
page.
I believe the reason there are these two label controls with almost the same functionality is (pre)historical.
In old versions of Windows (old as Windows 3.x), there was a practical limit of number of handles the whole system could have. So using handle-less label control was good way to save these precious system resources. That's why Borland introduced the TLabel.
TStaticText
TStaticText has a Window Handle and can accept focus whereas TLabel does not have a Window Handle and cannot accept focus
TStaticText allows the user to edit the text displayed whereas TLabel does not allow the user to edit the text displayed
TLabel
TLabel's caption property can be changed programmatically whereas TStaticText's Caption property cannot be changed programmatically
TLabel does not have a ShowAccelChar property whereas TStaticText does have a ShowAccelChar property

Draw an image instead of window caption

I need to do something which seems to be easy, but I'm searching for days with no success.
I have a window of fixed size (say 500*250) and need to replace the whole caption bar with a fixed size JPEG (or better PNG) image (say 500*25).
There are lots of samples talking about Glass, Aero, DWM, blah blah blah. But I just need to draw a fixed image!
I've already tried this, but it doesn't work:
procedure TForm1.Button1Click(Sender: TObject);
var
bmp:TBitmap;
DC:HDC;
begin
DC:=GetWindowDC(form1.Handle);
bmp:=tbitmap.Create;
bmp.SetSize(500, 25);
bmp.Canvas.TextOut(5,5,'Helloooooooooooooooooo');
BitBlt(dc,0,0,500,25,bmp.Canvas.Handle,0,0,SRCCOPY);
bmp.Free;
ReleaseDC(form1.Handle,DC);
end;
It should work both on XP and Vista/7. Please help.
P.S: I have Delphi XE.
You can do so by using VCL Styles.
You can change the appearance of the Windows caption bar like that by using the Delphi integrated Bitmap style designer to change a custom style and then use that Style in your application.
If you don't want to enforce the style to the whole application you can set the StyleElements property of the form to only include seBorder, this means that only the border aka caption of your application will be rendered using your custom style.
If you're working in Delphi XE2 then you won't be able to use the StyleElements property but that is just a minor obstacle, it just means that you will have to resort to using StyleHooks to implement the same behaviour and there is enough documentation on how to do that here.
Sadly, if your Delphi version is older then XE2 then you won't be able to use VCL Styles.
Another but rather unpleasant way would be to create a borderless form by changing the BorderStyle property to bsNone and then implementing your image in a way that it would act as a title bar, processing all actions made on the image and sending appropriate Messages to the application.
You can either:
Intercept the WM_NCPAINT message and custom-draw the caption bar manually.
Remove the caption bar altogether, by using SetWindowRgn() or overriding the CreateParams() method to remove the WS_CAPTION style, and then use the form's OnPaint event, or even a TImage, to display the graphic at the top of the form's remaining client area.
The simplest solution would be to use CreateParams() and TImage.

How to prevent form from being resized in Delphi?

How do I prevent my form from being resized? I don't want it to be maximized (which can be toggled via the property editor), but I don't want anyone to be able to drag-resize it. Am I missing something simple, or does this require a little bit of coding?
I'm using Delphi 2007.
TForm has the property you need. Set
BorderStyle to bsSingle
so that the form doesn't appear to be sizable, and it has the added benefit of actually not being sizable. :-)
You can set the BorderStyle to bsDialog.
Don't forget about the Constraint properties of TForm, i.e. MaxHeight, MinHeight, MaxWidth, MinWidth.
You can set the BorderStyle to bsSingle, too. That will give you a proper top level frame, with icon and everything.
And if you want to get really geeky (i.e. the answers above are better), you can intercept the RESIZE Windows message.
I would go with the Constraints property myself.
Cheers
Set borderstyle to bstoolwindow. The windows will only have a close button and title bar.

Resources