PDA

View Full Version : Threads?



Fernando
09-05-2003, 10:49 PM
Hi guys.
I'm a C++ programmer that started to program with Delphi, and have a few question..

I don't know what happens, but sometimes, when executing my program, a nice and uggly screen called 'CPU' appears. It has a lot of assembly coding, and in front of it, a message dialog with 'access violation at 0xbff, etc'.

I'm sure that my code is not wrong... And I think this problem is related to threads...

I'm not using threads on my application, but it seems that a lot of components in delphi use it.

When I execute my program, I have a few impression that after calling a function, the program doesn't wait until it finishs to return. The program returns, and continue executing the function on the background. And I think this cause the 'access violations' that I'm getting.

Is there a way to avoid this?

Thank you, and sorry for the bad english... (i'm brazillian).
Fernando.

Harry Hunt
09-05-2003, 11:18 PM
Well, of course all programmers would never admit that there's something wrong with their code, but it looks just like it.
Your problem may be thread-related, probably caused by one of the components you use (The components that come with Delphi are very reliable, so I guess you use 3rd-party components) or by your own code. Try to remove one component you use after the other to see which one causes the problem...

Fernando
10-05-2003, 12:00 AM
I looked at my code and found the function that is causing the error.

It's SwapBuffers.

When I call this function, sometimes the program crashes.

I looked at the Borland Help and there they said:

"A multithreaded application should flush the drawing commands in any other threads drawing to the same window before calling the SwapBuffers function."

What this means in practice?
Fernando

Fernando
10-05-2003, 01:17 PM
Hi. I started another application because the other one had a lot of errors.
Now, I want to construct everything in a right way.

Changing the threads topic, I would like to know why the Window Handle is not available when we override the Create Method when creating new components. And if it's possible to have a Create method with a Handle already available.

Thank you.