Funções no Delphi

Veja nesta dica algumas funções como: verificar se um componente já existe, substituir string, etc.

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;

 

//Inverte data

function TForm.InverteData(Data: TDateTime;sFormato:String='yyyy/mm/dd'): String;

begin

  Result := FormatDateTime(sFormato,Data);

end;

 

//Substitui string

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;

 

function TForm.SubstituiStr2(Velho,Novo,Linha: String): String;

 var t,p: Integer;

 begin

   repeat

t := Length(Velho);

p := Pos(Velho,Linha);

if p > 0 then begin

Delete(Linha,p,t);

Insert(Novo,Linha,p);

end;

   until p = 0;

   Result := Linha;

 end;

Ebook exclusivo
Dê um upgrade no início da sua jornada. Crie sua conta grátis e baixe o e-book

Artigos relacionados