Web Design and Web Development Forum

  1. #1
    Join Date
    Dec 2007
    Location
    New Hampshire, U.S.
    Age
    19
    Posts
    115
    Rep Power
    5
  2. machacker is on a distinguished road
  3. Delphi counter help

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    i := 0;
    Edit1.Text := (i + 1);

    When i click the button i want it to count "score", so everytime i click it will go 1,2,3... so on

    when i try to compile it says [Pascal Error] Unit1.pas(32): E2010 Incompatible types: 'string' and 'Integer'
    Reply With Quote Reply With Quote
  4. #2
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  5. bfsog is on a distinguished road
  6. Re: Delphi counter help

    Well, read the error. It is telling you you are mixing types.

    ToString

    Try
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    i := 0;
    Edit1.Text := (i + 1).ToString;
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  8. bfsog is on a distinguished road
  9. Re: Delphi counter help

    Furthermore, every time Button1 (very good naming convention) is clicked the variable i will be reset to one.

    Declare it outside of your procedure.
    Reply With Quote Reply With Quote
  10. #4
    Join Date
    Jul 2005
    Location
    Macedonia
    Age
    23
    Posts
    987
    Rep Power
    7
  11. Hypnotic is on a distinguished road
  12. Re: Delphi counter help

    I believe the function to convert int to string in delphi is IntToStr(),

    so that would be

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    i := 0;
    Edit1.Text := IntToStr(i + 1);
    end;
    Reply With Quote Reply With Quote
  13. #5
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  14. bfsog is on a distinguished road
  15. Re: Delphi counter help

    Well, the variable is still a Integer, we just need to convince the textbox that the value is okay to be assigned.

    Also you cannot do string = string + 1. Well perhaps you can but that is more like a concatenate.
    Reply With Quote Reply With Quote
  16. #6
    Join Date
    Dec 2007
    Location
    New Hampshire, U.S.
    Age
    19
    Posts
    115
    Rep Power
    5
  17. machacker is on a distinguished road
  18. Re: Delphi counter help

    Quote bfsog originally posted: View Post
    Furthermore, every time Button1 (very good naming convention) is clicked the variable i will be reset to one.

    Declare it outside of your procedure.
    How do i do that?

    i'm very new to this
    Reply With Quote Reply With Quote
  19. #7
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  20. bfsog is on a distinguished road
  21. Re: Delphi counter help

    You do it after any type definitions and before implementation.
    Reply With Quote Reply With Quote
  22. #8
    Join Date
    Dec 2007
    Location
    New Hampshire, U.S.
    Age
    19
    Posts
    115
    Rep Power
    5
  23. machacker is on a distinguished road
  24. Re: Delphi counter help

    Quote bfsog originally posted: View Post
    You do it after any type definitions and before implementation.
    so i make i := 0; after:
    Code:
    var
      Form1: TForm1;
      i : integer;
    so it should look like this
    Code:
    var
      Form1: TForm1;
      i : integer;
      i := 0;
    but when i try to run, it says
    [Pascal Error] Unit1.pas(25): E2004 Identifier redeclared: 'i'
    Reply With Quote Reply With Quote
  25. #9
    Join Date
    Sep 2005
    Location
    UK
    Age
    27
    Posts
    807
    Rep Power
    0
  26. bfsog is on a distinguished road
  27. Re: Delphi counter help

    Is that on the initial run or when you click the button?

    Take out the i:= 0 line in the button click event so your procedure will be something like

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    i := i + 1
    Edit1.Text := (i).ToString;
    Reply With Quote Reply With Quote

Similar Threads

  1. Delphi Image help
    By machacker in forum General Programming
    Replies: 1
    Last Post: 12-27-2007, 06:50 AM
  2. C++ 'V' Delphi
    By Adamwts in forum General Programming
    Replies: 20
    Last Post: 04-21-2007, 09:54 AM
  3. How to interface Fortran POwerStation 4 with Delphi 6
    By MasAnto in forum General Programming
    Replies: 3
    Last Post: 04-27-2006, 12:10 AM
  4. Have to know Pascal to learn Delphi?
    By Mala in forum General Programming
    Replies: 11
    Last Post: 02-04-2006, 01:28 PM