Data types incompatible with calling procedure

6

I'm having trouble calling the following procedure on my form :

procedure TDM_Maquinas.IBDSMaquinasCOD_LINHASetText(Sender: TField; const Text: string);
begin
  if Text <> '' then
  begin
    if Text = 'Linha 1' then
      sender.AsInteger := 1
    else if Text = 'Linha 2' then
      Sender.AsInteger := 2
  end;
end;

On the save button:

procedure TForm.salvar(Sender: TObject);
var
 ValorLinha : Integer;
begin
 ValorLinha := DM_Maquinas.IBDSMaquinasCOD_LINHASetText(DBComboBox2.Field, 'Linha 1'); //erro
end;

I'm having the wrong line up:

  

E2010 Incompatible types: 'Integer' and 'procedure, untyped pointer   or untyped parameter '

If we change the type of the ValueLine variable to String the error persists.

    
asked by anonymous 24.08.2017 / 22:46

2 answers

3

Exactly as reported in the comment, you need a function to return the desired value, or feed a variable into the procedure!

Function:

function TDM_Maquinas.IBDSMaquinasCOD_LINHASetText(Sender: TField; const Text: string): Integer;
begin
  if Text <> '' then
  begin
    if Text = 'Linha 1' then
      Result := 1
    else if Text = 'Linha 2' then
      Result := 2
  end;
end;

Or by modifying the procedure to feed an external variable:

procedure TDM_Maquinas.IBDSMaquinasCOD_LINHASetText(Sender: TField; const Text: string);
begin
  _VariavelExterna := 0;

  if Text <> '' then
  begin
    if Text = 'Linha 1' then
      _VariavelExterna := 1
    else if Text = 'Linha 2' then
      _VariavelExterna := 2
  end;
end;

On the save button:

procedure TForm.salvar(Sender: TObject);
var
  ValorLinha : Integer;
begin
  DM_Maquinas.IBDSMaquinasCOD_LINHASetText(DBComboBox2.Field, 'Linha 1');
  ValorLinha := _VariavelExterna; 
end;

For all cases the best and correct option is the function!

    
25.08.2017 / 13:19
0

You could create one more parameter in the procedure, to feed the variable.

Example:

procedure TDM_Maquinas.IBDSMaquinasCOD_LINHASetText(Sender: TField; const Text: string; aValorLinha: Integer);
begin
  if Text <> '' then
  begin
    if Text = 'Linha 1' then
      sender.AsInteger := 1
    else if Text = 'Linha 2' then
      Sender.AsInteger := 2;
    aValorLinha := Sender.AsInteger;
  end;
end;

On the Save button:

procedure TForm.salvar(Sender: TObject);
var
 ValorLinha : Integer;
begin
  DM_Maquinas.IBDSMaquinasCOD_LINHASetText(DBComboBox2.Field, 'Linha 1', ValorLinha);
end;
    
29.11.2017 / 12:45