Procedures and functions, referred to collectively as routines, are self-contained statement blocks that can be called from different locations in a program. A function is a routine that returns a value when it executes. A procedure is a routine that does not return a value.
Let's change the code a little so that there is no cognitive dissonance. )) The function will return true if the field is added, and false if the field already exists.
Function Add_newfield(tabela,novo_campo,tipo,e_default,dado: string):boolean;
var
ColResults: TDataset;
begin
Result := True;
SqlQuery('pragma table_info(['+tabela+']) ',ColResults);
while not ColResults.Eof do
begin
if UpperCase( ColResults.FieldByName('name').asString ) = UpperCase( novo_campo ) then
begin
Result := False;
Break;
end;
ColResults.Next;
End;
ColResults.Free;
If Result then
Begin
SqlExecute('ALTER Table ['+tabela+'] ADD COLUMN ['+novo_campo+'] '+tipo+' '+E_DEFAULT+' '+dado+' ');
if length(trim(dado)) > 0 then
sqlexecute('UPDATE ['+tabela+'] SET ['+novo_campo+'] ='+dado+' ');
End;
end;