Delaying a lot of time when shutdown the application, why?

Hi all Gurus!!

I'm programming an application with Delphi 3.0. I have a lot of controls on it... one of them is a StringGrid control, which has initially only 1 row and 1 column. When I run the program and I don't add any lines to the grid, all is OK... when I close the application, it closes immediately, that is, delphi shows the properties window and I can continuing programming. The problem is when inside the application, I fill the grid with a lot of rows... more than 55000.... and only 1 column... then.. if I close the application... the window is closed... but the properties window is shown after several minutes, that is... a great delay before application really closes.. so I have to make a Program Reset using the menu option.

How can I fix it?
Thanks in advance,
Who is Participating?
rwilson032697Connect With a Mentor Commented:

There is a much better, more elegant way.

Hold the information you would add to the stringgrid in, say, a TList (or however you cirrently do it). Set the stringgrid to have 55,000 rows. Write a handler for the OnDrawCell event in the list (which is called for each cell) and draw the text into the cell (see example below...).

procedure TMyForm.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
                                                            Rect: TRect; State: TGridDrawState);
    Stringgrid.Canvas.Textout(rect.left + 2, + 2, GetTheString(Row));

This means you don't need to mess around with a separate scroll bar and everything exits nice and quickly.



Why would you need so many cells???

I think this cannot be avoided because you have two many cells.

Why don't you free/destoy the StringGrid first before you end the application.

Another way may be writing a component from drawgrid without using stringlist to store your data in the memory. Shoud not be too difficult.

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

skelAuthor Commented:
Well.. I will explain what I need to do... I'm doing a debugger of an embedded system. In that string grid I'm storing machine instructions (Mnemonics) of a 64 K memory. As the instructions has operation codes of at least 3 bytes,  when I have read all the memory, it results that I have a little more than 55000 rows.
I have other 3 more string grids, one for displaying External Memory of the system, one for Internal Memory, and the last for displaying the Stack Memory. These others don't have many rows (4096, 16 and 32 rows, respectively).

Any suggestion of how can I do it?
Thanks a lot in advance

In the OnCloseQuery you could hide the form so that the app would seem to close instantly.


Please tell us what happens when you run this app outside delphi
Hi All,

I tried to reproduce this (in D4) so that I might debug the clean up code for TStringGrid.

Unfortunately the source for GRIDS in D4 seems to have some bug in it when trying to add values to the Cells.

Therefore I could not get to the end of my routine to check, what was going on - althought I suspect as KJTeng suggests that this code is as good as it is going to get.

Another point was that when I added a processmessages in the loop I wrote to populate 55000 cells I noted that this did speed up this loop?

Anyway I agree that this is unlikely to be improvable.

what about the following:

you fix the height of the stringgrid-control so that there are let's say always 10 rows displayed.
you create a TStringLis to manage all your strings.
you create a function which controls a "window" over this TStringList, always displaying the actual row plus the next 9 rows (handling of begin/end of the list shouldn't be too hard) in your StringGrid.
when the user scrolls the window, the index into the TStringList must be set correspondingly and then the function to display the virtual window in the StringGrid must be invoked.
when closing the app, you free the TStringList.
i think, this should speed up the closing process.

try and tell me.

Black Death.
skelAuthor Commented:
Yes, I understand the idea... now... how can I control the thumb position of the scroll bar? for example.. as I am displaying only 10 rows of the grid.. scrollbar will fit to this visible rows. If I am, for example, displaying the string number 28000, the thumb need to be almost in the middle of scroll bar, how can I do it?

ya, that's a point...

you won't have a matching scrollbar, because the StringGrid is of height 10 and the StringList to be displayed has 10 entries. so you'll have to add two buttons by yourself. in addition to these you can place a vertical trackbar next to the stringgrid (between the buttons) and manage it manually. that's not so funny, i know...
can't think of any better method right now. when i've got a new idea, i'll let ya know, o.k.?

so far,

Black Death.
ugh. that was stupid.
of course you'll place a TScrollBar next to the Grid and switch off the ScrollBars of the Grid itself. sorry...
so. skel.
meanwhile i've slammed together a little demo to show you what i've meant. it's not very nice, but it worx. post your email-address here and i'll mail it to you. if there are any questions, mail me:

Black Death.
skelAuthor Commented:
Thanks a lot Black Death... I have placed a TScrollBar next to the TStringGrid (without displaying its own scrollbar of course).... that's works very well... thanks a lot for your help :)

no sweat ;-)=)

like i've said before; if you want the demo, mail me.


Black Death.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.