Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: check stringgrid cell first and than if it is not empty save



Permlink Replies: 4 - Last Post: Sep 28, 2015 9:49 AM Last Post By: Remy Lebeau (Te...
Ferhat Ergin Tu...

Posts: 16
Registered: 7/17/15
check stringgrid cell first and than if it is not empty save
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2015 4:29 AM
i try to check stringgrid cell first and than if it is not empty save it. but i get message " '' is not valid integer value"

for i := 1 to AdvStringGrid1.RowCount-1 do
begin
if AdvStringGrid1.Cells[1,i]>'' then
begin
for j := 0 to form3.ListBox3.Items.Count-1 do
if (strtoint(advstringgrid1.Cells[17,i])>strtoint(form3.Edit1.Text)) and (AdvStringGrid1.Cells[4,i]<>form3.ListBox3.Items[j]) then
begin
adotable1.Append;
adotable1TARIH.Value:=strtodate(AdvStringGrid1.Cells[0,i]);
adotable1UCUS.Value:=(AdvStringGrid1.Cells[1,i]); //tarih
adotable1KLIM.Value:=(AdvStringGrid1.Cells[2,i]);
adotable1VLIM.Value:=(AdvStringGrid1.Cells[4,i]);
adotable1TIP.Value:=(AdvStringGrid1.Cells[6,i]);
adotable1PFS.Value:=(AdvStringGrid1.Cells[17,i]);
adotable1.post;
advstringgrid1.Rows[i].Clear;
end;
end;
end;

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: check stringgrid cell first and than if it is not empty save
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2015 4:56 AM   in response to: Ferhat Ergin Tu... in response to: Ferhat Ergin Tu...
Ferhat

if AdvStringGrid1.Cells[1,i]>'' then
begin
for j := 0 to form3.ListBox3.Items.Count-1 do
if (strtoint(advstringgrid1.Cells[17,i])>strtoint(form3.Edit1.Text)) and (AdvStringGrid1.Cells[4,i]<>form3.ListBox3.Items[j]) then
begin

' is not valid integer value" is coming from strtoint. You have two places where it can be generated

strtoint(advstringgrid1.Cells[17,i])

and

strtoint(form3.Edit1.Text)

and you're not testing either of those to see if there is a valid number in them. You can either do that or use StrToIntDef and supply suitable defaults

Roy Lambert

Ferhat Ergin Tu...

Posts: 16
Registered: 7/17/15
Re: check stringgrid cell first and than if it is not empty save
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2015 5:13 AM   in response to: Roy Lambert in response to: Roy Lambert
sorry i wrote wrong :( i want if cell is not empty then bla bla...

if AdvStringGrid1.Cells[1,i]<>'' then
begin
for j := 0 to form3.ListBox3.Items.Count-1 do
if (strtoint(advstringgrid1.Cells[17,i])>strtoint(form3.Edit1.Text)) and (AdvStringGrid1.Cells[4,i]<>form3.ListBox3.Items[j]) then
begin
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: check stringgrid cell first and than if it is not empty save
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2015 5:50 AM   in response to: Ferhat Ergin Tu... in response to: Ferhat Ergin Tu...
Ferhat

Same answer applys

if AdvStringGrid1.Cells[1,i]<>'' then
begin
for j := 0 to form3.ListBox3.Items.Count-1 do
if (strtoint(advstringgrid1.Cells[17,i])>strtoint(form3.Edit1.Text)) and (AdvStringGrid1.Cells[4,i]<>form3.ListBox3.Items[j]) then
begin

You test [1,i] to see if its empty, that tells you nothing about what's in [17,i] or [form3.Edit1.Text which are the ones you're trying to convert to integers.

Roy Lambert
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: check stringgrid cell first and than if it is not empty save
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2015 9:49 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy wrote:

You can either do that or use StrToIntDef and supply suitable defaults

I would use TryStrToInt() instead.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02