Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Validation on an interger Posted by sarkiemarkie on 10 Feb 2006 at 2:45 PM
This message was edited by sarkiemarkie at 2006-2-10 14:46:27

procedure TForm2.Edit1Exit(Sender: TObject);
{the member number is checked to see if it contains only numbers}
var
i:integer;
ok,inuse:boolean;
begin
ok := true;
inuse:=false;
  for i:= 1 to length(edit1.text) do       {checks the member Number for digits}
  begin
    if not (edit1.text[i] in Digits) then
      ok := false;
  end;

  assignfile(memberfile,'members.dat');
  reset(memberfile);
  read(memberfile,memberrecord);
  for i:= 1 to filesize(memberfile) do
    if memberrecord.Membernumber = strtoint(edit1.text) then
        inuse:=true;



if ok=false then edit1.Color:=clLime;
if inuse=true then edit1.Color:= clyellow;   {checks for duplication}
if length(edit1.Text)=0 then edit1.Color:=clred {checks for presence}
else edit1.color:=clWhite;


end;


the for loops doint work. It says that the i variable is "inaccessable here due to optimization" when i put a watch on the i and thats why the for loops are not working

whats wrong?


Report
Re: Validation on an interger Posted by zibadian on 10 Feb 2006 at 3:14 PM
: This message was edited by sarkiemarkie at 2006-2-10 14:46:27

:
procedure TForm2.Edit1Exit(Sender: TObject);
: {the member number is checked to see if it contains only numbers}
: var
: i:integer;
: ok,inuse:boolean;
: begin
: ok := true;
: inuse:=false;
:   for i:= 1 to length(edit1.text) do       {checks the member Number for digits}
:   begin
:     if not (edit1.text[i] in Digits) then
:       ok := false;
:   end;
: 
:   assignfile(memberfile,'members.dat');
:   reset(memberfile);
:   read(memberfile,memberrecord);
:   for i:= 1 to filesize(memberfile) do
:     if memberrecord.Membernumber = strtoint(edit1.text) then
:         inuse:=true;
: 
: 
: 
: if ok=false then edit1.Color:=clLime;
: if inuse=true then edit1.Color:= clyellow;   {checks for duplication}
: if length(edit1.Text)=0 then edit1.Color:=clred {checks for presence}
: else edit1.color:=clWhite;
: 
: 
: end;

:
: the for loops doint work. It says that the i variable is "inaccessable here due to optimization" when i put a watch on the i and thats why the for loops are not working
:
: whats wrong?
:
:
Which line does it say that? I cannot see where that error would occur.
Report
Re: Validation on an interger Posted by pritaeas on 10 Feb 2006 at 7:20 PM
You could also use:

var
i: Integer;

try
i := StrToInt(Edit1.Text);
except
{ Edit1.Text is not an integer }
i := -1;
end;

if i <> -1 then begin
{ i is a valid number }
end;
Report
Re: Validation on an interger Posted by sarkiemarkie on 11 Feb 2006 at 5:04 AM
: : This message was edited by sarkiemarkie at 2006-2-10 14:46:27

: :
procedure TForm2.Edit1Exit(Sender: TObject);
: : {the member number is checked to see if it contains only numbers}
: : var
: : i:integer;
: : ok,inuse:boolean;
: : begin
: : ok := true;
: : inuse:=false;
: :   for i:= 1 to length(edit1.text) do       {checks the member Number for digits}
: :   begin
: :     if not (edit1.text[i] in Digits) then
: :       ok := false;
: :   end;
: : 
: :   assignfile(memberfile,'members.dat');
: :   reset(memberfile);
: :   read(memberfile,memberrecord);
: :   for i:= 1 to filesize(memberfile) do
: :     if memberrecord.Membernumber = strtoint(edit1.text) then
: :         inuse:=true;
: : 
: : 
: : 
: : if ok=false then edit1.Color:=clLime;
: : if inuse=true then edit1.Color:= clyellow;   {checks for duplication}
: : if length(edit1.Text)=0 then edit1.Color:=clred {checks for presence}
: : else edit1.color:=clWhite;
: : 
: : 
: : end;

: :
: : the for loops doint work. It says that the i variable is "inaccessable here due to optimization" when i put a watch on the i and thats why the for loops are not working
: :
: : whats wrong?
: :
: :
: Which line does it say that? I cannot see where that error would occur.
:

it doesnt come up as an error but the for statements werent working properly so i put a watch on i and where it came to the for statements, thats the message that appear in i where an integer should have been.

Report
Re: Validation on an interger Posted by zibadian on 11 Feb 2006 at 1:01 PM
: : : This message was edited by sarkiemarkie at 2006-2-10 14:46:27

: : :
procedure TForm2.Edit1Exit(Sender: TObject);
: : : {the member number is checked to see if it contains only numbers}
: : : var
: : : i:integer;
: : : ok,inuse:boolean;
: : : begin
: : : ok := true;
: : : inuse:=false;
: : :   for i:= 1 to length(edit1.text) do       {checks the member Number for digits}
: : :   begin
: : :     if not (edit1.text[i] in Digits) then
: : :       ok := false;
: : :   end;
: : : 
: : :   assignfile(memberfile,'members.dat');
: : :   reset(memberfile);
: : :   read(memberfile,memberrecord);
: : :   for i:= 1 to filesize(memberfile) do
: : :     if memberrecord.Membernumber = strtoint(edit1.text) then
: : :         inuse:=true;
: : : 
: : : 
: : : 
: : : if ok=false then edit1.Color:=clLime;
: : : if inuse=true then edit1.Color:= clyellow;   {checks for duplication}
: : : if length(edit1.Text)=0 then edit1.Color:=clred {checks for presence}
: : : else edit1.color:=clWhite;
: : : 
: : : 
: : : end;

: : :
: : : the for loops doint work. It says that the i variable is "inaccessable here due to optimization" when i put a watch on the i and thats why the for loops are not working
: : :
: : : whats wrong?
: : :
: : :
: : Which line does it say that? I cannot see where that error would occur.
: :
:
: it doesnt come up as an error but the for statements werent working properly so i put a watch on i and where it came to the for statements, thats the message that appear in i where an integer should have been.
:
:
The second loop is not necessary, because during that loop the memberrecord value and the edit1.text do not change, thus the if-then will not change after the first run. Delphi optimalizer probably removed the loop, and kept the if-then statement within it.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.