Error E2033 Types of current and formal var Parameters must be identical. How To Troubleshoot?

Asked

Viewed 32 times

3

I’m trying to write a Project in Delphi 10.
Procedure calls a form I use to display error messages. But when I try to make things work, Delphi gives an error like:

[dcc32 Error] UntPrincipal.pas(6318): E2033 Types of actual and formal var parameters must be identical

My previous

...
  public
       procedure ChamaMsg(var TipoMsg: Integer; TextMeg: string);
  end;
...
procedure TfrmPrincipal.ChamaMsg(var TipoMsg: Integer; TextMeg: string);
begin
  IMsg := TipoMsg;
  if frmSplash = nil then
    Application.CreateForm(TfrmSplash, frmSplash);

  frmSplash.SplashText.Caption := TextMeg;
  frmSplash.ShowModal;

  FreeAndNil(frmSplash);
end;

As I call Procedure:

// vMsg eu monto o texto para exibir na telinha da mensagem. 
vMsg  := 'Este Item ('+IntToStr(DMR.Produtos_ID_PRODUTO.AsInteger)+') não está presente neste Pedido!'+#13+#13+#13+'(Esc) Para Sair.';

ChamaMsg(1, vMsg);

What can be the solution to this error ... Thank you.

1 answer

3

In the procedure statement you used var TipoMsg: Integer Therefore, Delphi identifies the TipoMsg as a pointer/reference in memory.

This enables you to rewrite the contents of the parameter within the procedure TipoMsg so that whoever called him may receive a value other than that which he sent.

Therefore, you cannot use:

ChamaMsg(1, vMsg);

For 1 cannot be considered a pointer/reference.

Try to use

var
  vValor: Integer;
begin
  vValor := 1;
  ChamaMsg(vValor, vMsg);

  // dentro do procedimento é possível reescrever o valor do parâmetro  

  if vValor <> 1 then
  ...
end;
  • 1

    Oops!!! Beauty, I will try to do as it is in your explanation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.