Inputado value does not appear

Asked

Viewed 70 times

-1

I’m having a doubt in an exercise where I have to show which number is the least or the most insane.

But it’s not bringing the right result.

Segue o código.
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    lblN1: TLabel;
    lblN2: TLabel;
    edtN1: TEdit;
    edtN2: TEdit;
    btnMostrar: TButton;
    procedure btnMostrarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.btnMostrarClick(Sender: TObject);
var
  edtN1 : Integer;
  edtN2: Integer;

begin

    if edtN1.Size > edtN2.Size then
      ShowMessage('O número 1 é o maior!')
    else
      ShowMessage('O número 2 é o maior!');
end;

end.

2 answers

4

You are using the Size property.... which does not tell you anything about what was typed. Need to use the

if StrToInt(edtN1.Text)> StrToInt(edtN2.Text) then
  • I realized that edt always receives string, so soon you have to convert. Thanks however gave another error "integer does not containt a Member named 'Text'

  • @Matheuslima the error presented integer does not containt a member named 'Text is exactly what I answered.

  • Matheus I can bet you put a ')' in the wrong place :D That code I put there has to compile... Certainly not pos Strtoint(edtN1). Text instead of Strtoint(edtN1.Text)?

3

Let’s go to the problem itself. The logical test is wrong, because there are two variables with the same name of the components.

And in the pascal it will give priority to the local variables.

You did not receive build error because Integer has a function called Size.

The correct would be to test as already answered: if StrToInt(edtN1.Text)> StrToInt(edtN2.Text) then

or

edtN1 := StrToInt(edtN1.Text);
edtN2 := StrToInt(edtN2.Text);

if edtN1 > edtN2 then
...

Browser other questions tagged

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