Add space after finding a character

1

I have the following code that adds the contents of a button and a space after clicking

   procedure TForm3.Button1Click(Sender: TObject);
      begin
        if count = 0 then
          Edit1.Text := Edit1.Text + TLabel(Sender).caption+ ' ';

        if count = 1 then
          begin
            Edit2.Text := Edit2.Text + TLabel(Sender).caption+ ' ';
          end;
      end;

Saida: Dose = Max + Min

and another situation for number, which does not apply the spaces:

    procedure TForm3.Button29Click(Sender: TObject);
    begin
         if count = 0 then
          Edit1.Text := Edit1.Text + TLabel(Sender).caption;

        if count = 1 then
          begin
            Edit2.Text := Edit2.Text + TLabel(Sender).caption;
          end;

    end;
Saida: Dose = 10

But I was thinking that after the number could find a text and the way I would do the character after the number would come out

Saida: Dose = 10AND 20

Where the correct one would be:

Saida: Dose = 10 AND 20

How to handle the function so that when the next character after the number is a the letter, it adds a space?

    
asked by anonymous 25.02.2016 / 15:30

1 answer

2

You could create a function in the following templates, where SetOfChar is a declared constant:

SetOfChar = set of 'A'..'z';

function Concatena(const TextoEdit, Caption: String): String;
begin
  if TextoEdit = '' then
    Result := Caption
  else if TextoEdit in SetOfChar then
    Result := TextoEdit + ' ' + Caption
  else
    Result := TextoEdit + Caption;
end;
    
25.02.2016 / 16:39