[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Another one, hopefully simple - clearing string grid in delphi?

Posted on 2009-04-19
2
Medium Priority
?
324 Views
Last Modified: 2013-11-23
Hi there, this is some code to clear a string grid that is failing. It occurs to me that there is probably a stupidly simple way of doing this compared to what I'm trying to do, but there you go...

Code's below. It fails to clear the string grid but otherwise works.
procedure TFrmEPOS.BtnTransactionVoidClick(Sender: TObject);
var count: integer;
begin
  if BtnEposTotal.Enabled then
    for count := 0 to Strrow do
      begin
      StrGridTransaction.Cells[1,Strrow]:='';
      StrGridTransaction.Cells[0,Strrow]:='';
      end
    else
      begin
     Strrow := Strrow +1;
      for count := 0 to Strrow do
        begin
        StrGridTransaction.Cells[1,Strrow]:='';
        StrGridTransaction.Cells[0,Strrow]:='';
        end;
      MmoTransactionTotal.Text:='';
      BtnEposAdd.Enabled := true;
      BtnEposDelete.Enabled := true;
      BtnEposQuantity.Enabled := true;
      BtnEposTotal.Enabled := true;
    end;
end;
end.

Open in new window

0
Comment
Question by:TTRMW
2 Comments
 
LVL 6

Accepted Solution

by:
JosephGlosz earned 1000 total points
ID: 24181497
StrRow seems to be some sort of global since your code compiles OK.  This means that somewhere outside this function, it has to be set correctly.  if it is 0, for example, then that first FOR loop won't execute even once.  So, make sure it is set somewhere to at least 1.

Also, it is possible that your loops should look like this:

    for count := 0 to Strrow do
      begin
      StrGridTransaction.Cells[1,Count]:='';
      StrGridTransaction.Cells[0,Count]:='';
      end

because otherwise (the way you originally had it) it just keeps doing the same thing over and over.  That is, your way, let's say StrRow was 5 then the loop would be

    for count := 0 to 5 do
      begin
      StrGridTransaction.Cells[1,5]:='';
      StrGridTransaction.Cells[0,5]:='';
      end

so you see, it keeps blanking out just those same two cells.  In this case, 6 times.

And since Count is 0 based, I'll bet you really want something like this:

    for count := 0 to Strrow-1 do
      begin
      StrGridTransaction.Cells[1,Count]:='';
      StrGridTransaction.Cells[0,Count]:='';
      end

But still, make sure that StrRow is properly initialized somewhere!  To something more than 0!
0
 

Author Closing Comment

by:TTRMW
ID: 31572072
Great stuff, cheers.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

834 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