Recent

Author Topic: What's wrong with my programme?  (Read 5564 times)

Artem

  • New Member
  • *
  • Posts: 15
What's wrong with my programme?
« on: November 30, 2016, 07:08:18 pm »
var
  Form1: TForm1;
  k:string;
  b:real;
  c:qword;
           

......

procedure TForm1.Button1Click(Sender: TObject);
begin
K:=Edit1.text;
        try
strtoint(l)
       except
       showmessage('Incorrect input!');
       Edit1.clear;
       Edit1.setfocus;
       end;

  b:=(strtoint(k)-32)/2;
  c:=inttostr(b);
       ComboBox1.Style:=csDropDownList;

       IF  Combobox1.ItemIndex =0
       then label1.caption:=c;

end;   

So my errors are
Compile Project, Target: temp.exe: Exit code 1, Errors: 2
unit1.pas(56,16) Error: Incompatible type for arg no. 1: Got "Real", expected "QWord"
unit1.pas(60,30) Error: Incompatible type for arg no. 1: Got "QWord", expected "TTranslateString"

What should I do?
Thanks in advance =)

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: What's wrong with my programme?
« Reply #1 on: November 30, 2016, 07:15:41 pm »
Basically you're mixing types.


var
  Form1: TForm1;
  k:string;
  b:real;
  c:qword;
           

......

procedure TForm1.Button1Click(Sender: TObject);
begin
K:=Edit1.text;
        try
strtoint(l) // What's this? It should be StrToInt(k)
       except
       showmessage('Incorrect input!');
       Edit1.clear;
       Edit1.setfocus;
       end;

  b:=(strtoint(k)-32)/2;
  c:=inttostr(b); // This is not possible, must be trunc(b)
       ComboBox1.Style:=csDropDownList;

       IF  Combobox1.ItemIndex =0
       then label1.caption:=c; // And this is wrong too, must be IntToStr(c)

end;   

Artem

  • New Member
  • *
  • Posts: 15
Re: What's wrong with my programme?
« Reply #2 on: November 30, 2016, 07:23:57 pm »
Ooooh thanks a lot really, I'm so stupid , I'm just beginner, ty =)

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: What's wrong with my programme?
« Reply #3 on: November 30, 2016, 10:39:31 pm »
Don't worry, just try to figure the data types when you write the code.

This is not like java that has automatic conversion from numbers to string, you must specify the conversion with a function.

* But of course automatic conversion is possible to achieve with some operator overloading, but is not your case as you're just starting with Pascal.

 

TinyPortal © 2005-2018