2
votes

Currently, the iOS TEdit when it brings up the Keyboard, will have the keyboard in Caps for first letter.

I would like to turn off Keyboard auto going into Caps for first letter for specific TEdit. Some TEdits I would want to retain first letter as capitalized, eg Names.

I can't use the TEdit.CharCase feature as it forces all input in TEdit to lowercase.

What I want is that user can Type in Mixed Case if they choose to but the Keyboard has to be in lowercase when TEdit first comes into focus.

How do I do this in Delphi 10.4.1?

2

2 Answers

2
votes

You can control the default behavior of virtual keyboard by changing the KeyboardType property.

The KeyboardType property controls both the visual look of the virtual keyboard so that it is the most suitable for expected input (text, URL, phone number, etc.) as well as whether some advanced features like Spelling, Word Completion, or even Auto Correct which can automatically correct spelling errors or make sure that words at the beginning of sentence start with Capital letter.

I believe in your case you would like to use Alphabet KeyboardType instead of the Default.

2
votes

One possible way to solve this is to:

Create a unit with a Boolean reference (or add to an existing unit) that is exposed publicly, e.g:

unit iOSPatch;

interface

var
  DisableAutoCapitalization: Boolean;

implementation

end.

Create a copy of source\fmx\FMX.Platform.iOS.pas and put it in the project compile path (such as the project folder)

Modify the copy of FMX.Platform.iOS by adding the unit name from the first step to the implementation uses clause, e.g.:

implementation
  
uses
  iOSPatch,
  System.Classes, System.SysUtils, System.Types, System.UITypes, System.TypInfo, System.Messaging, System.RTLConsts,
  // ... rest of uses clause snipped

Modify the TFMXViewBase.autocapitalizationType method to look like this:

function TFMXViewBase.autocapitalizationType: UITextAutocapitalizationType;
begin
  if DisableAutoCapitalization or FPassword or not (FKeyboardType in [TVirtualKeyboardType.Default, TVirtualKeyboardType.Alphabet, TVirtualKeyboardType.NamePhonePad]) then
    Result := UITextAutocapitalizationTypeNone
  else
    Result := UITextAutocapitalizationTypeSentences;
end;

Use the OnEnter event of every edit to set DisableAutoCapitalization to True/False depending on your needs

Alternatively, if you want it to apply to all edits regardless, you could modify TFMXViewBase.autocapitalizationType to set Result to UITextAutocapitalizationTypeNone and ignore the first step.

Unfortunately I can't test this right now as something has gone haywire with deployment on my machine

EDIT

I've managed to solve my deployment issue, and tested the code above, which works. Slight side-effect: the Shift button on the VK appears as "pressed" briefly