Funções no Delphi

// verifica se um componente já existe
function TForm.TestaComponente(Nome: String): boolean;
var i: integer;
begin
  result := False;
  for i := 0 to (Application.ComponentCount - 1) do begin
    result := (Application.Components[i].Name = Nome);
    if result then break;
  end;
end;


function TForm.InverteData(Data: TDateTime;sFormato:String='yyyy/mm/dd'): String;
begin
  Result := FormatDateTime(sFormato,Data);
end;


function TForm.SubstituiStr(Velho,Novo,Linha: String): String;
var t,p: Integer;
begin
  t := Length(Velho);
  p := Pos(Velho,Linha);
  if p > 0 then begin
     Delete(Linha,p,t);
     Insert(Novo,Linha,p);
  end;
  Result := Linha;
end;