1
votes

I am in the process of creating a custom component descended from a FMX TEdit control. One requirement is I need this control to be able to mimic/act like a combed field. This requires a max length and increased spacing between characters so the characters fall between the vertical lines. Please see image below for example.

Combed Fields Example

The max length functionality is already part of the TEdit control but I am unable to find any information on how to increase the spacing between characters. I've looked into Delphi source code and have not come across anything that might be helpful. The font settings I came across were the typical font styles of bold/italic and font alignment of leading/center/trailing.

I also came across TFontStretch under TFontStyleExt but was not able to find out much more about it. Delphi's own website states "Embarcadero Technologies does not currently have any additional information." I'm not even sure this is related to what I'm looking for but I'm shooting from the hip on this one.

If anyone can point me in the right direction it would be much appreciated.

Thank you

2
You'll need to implement that from scratch.David Heffernan
Stretching the font is unlikely to work well, and certainly won't work unless your font is fixed. Instead treat each character as a separate string, and each box in your comb as a separate rectangle to draw that character in.Dsm
After digging around some more I think you're correct @DavidHeffernan. I'm going to have to make this from scratch. Thanks for the input.CKilpatrick

2 Answers

0
votes

I think that the best solution for your would be to use one of Monospaced fonts

If you can't find Monospaced ont that has desired character with to fit properly into your control you might want to use one of many font editing tools that you can find online to make necessary changes to your desired font.

And the best thing about using of Monospaced font is that you can use it in just about every FMX control that allows you to specify which font to use.

Do note that you will probably have to ship this custom font with your application and then dynamically register it at application start and unregister it at application close.

0
votes

I used this to implement a serial key typing style:

procedure TForm4.Edit1Typing(Sender: TObject);
var
atext,tmp_str,d_str:unicodestring;
index:integer;
begin
if not(edit1.Text.Length>=30)then   // 30 is the max length
  begin
  ///////////////// take ' ' out  (space between letters)
  atext:=edit1.Text;
  tmp_str:='';
  if not(edit1.Text.Length=0) then
    begin
    for index := 1 to Length(aText) do
      begin
      if not(aText[index]=' ')then
        begin
        tmp_str:=tmp_str+aText[index];
        end;

      end;
    end;
  ///////////////// now put the data back to the edit with the space
  d_str:='';
  if not(Length(tmp_str)=0) then
    begin
    for index := 1 to Length(tmp_str) do
      begin
      d_str:=d_str+tmp_str[index]+' ';
      end;
    end;
  edit1.Text:=d_str;
  edit1.CaretPosition:=length(d_str)-1;
  end;
end;

Override your component Ontyping event handler, this code puts a 'space' between letters so they would be drawn within each rectangle.

Make sure that your font size would allow that.

This is the result. enter image description here