Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String and Integer

Posted on 2000-03-20
10
Medium Priority
?
287 Views
Last Modified: 2010-04-04
I am very new to delphi, and I am kinda confused abotu this...below is my code.

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
s: string;
begin
button2.Enabled := true;
for i := 0 to 999999 do
begin
s := edit1.text;
s := s + 1;
edit1.text := s;
sleep(500);
end;
end;

end.


and I get an error about converting strings and crap like that, can some one fix this code to get it to work. Thanks
0
Comment
Question by:BrianG14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 1

Accepted Solution

by:
Indefrei earned 20 total points
ID: 2637738
Try to change to this

s: Integer; // see here
begin
                   button2.Enabled := true;
                   for i := 0 to 999999 do
                   begin
                   s := StrToInt(edit1.text); // Hopefully Text is an Integer !
                   s := s + 1;
                   edit1.text := IntToStr(s);
Regards
Indi
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2637750
Ps.
Sleep(500)
Sounds, as if you should use a Timer instead
0
 

Author Comment

by:BrianG14
ID: 2637752
what happens if the text is not a int...and it tries to convert a string to a int and its really a string...?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Indefrei
ID: 2637769
Well,
I think then you get an unpredictable Number
so, you better take care, that the input is a number
0
 

Expert Comment

by:jan_yt
ID: 2637780
You can try this. Think you want a "counter"? Not '1111.....'?

procedure TForm1.click(Sender: TObject);
var
{Changed this to longint }
 i : longint;
 s: string;

begin
 { Just to be sure it don't have a default text like "edit1.text" }
 edit1.text := '0';

for i := 0 to 999999 do
begin
 s := edit1.text;
{ Convert the text to an integer, add 1 and convert back to string }
 s := inttostr(strtoint (s) + 1);
 edit1.text := s;
{ If you want to see your counter you should use a refresh }
 form1.Refresh;
 sleep(500);
end;
0
 

Author Comment

by:BrianG14
ID: 2638364
is there any way to get the current x, y of the mouse and is there any way to change the x, y of the mouse. Thanks!
0
 

Expert Comment

by:frangers99
ID: 2638645
What indi said is correct, but i'll try and make this clearer for you.

Edit box fields only accept strings. As you probably know strings are words etc. If you want to work with integers you need to convert them into a integer ie.

var
number:integer;

number:=strtoint(edit1.text);

then to convert the number back to an editbox after you have played around with it. do...

edit1.text:= inttostr (number);

hope this will help you.

Andrew
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2642166
Yes, BrianG14
there are ways to get the current x, y of the mouse and there is a way to change the x,y of the mouse
but what do you expect for just poor 5 pts
Indi
0
 

Author Comment

by:BrianG14
ID: 2647743
well, I have 200 points...could those change your mind...if I get a good anwser maybe you could get them :D
0
 

Expert Comment

by:frangers99
ID: 2647950
why don't you give your five points to somebody and then open the xy as a new question.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question