//時間のかかる処理の例上記のプログラムを実行すると、計算している間ウィンドウの移動などの処理がいっさい できなくなります。しかし、ループの中にProcessMessagesを入れる事でこの問題は解消 されます。
Graphics::TBitmap *bit = new Graphics::TBitmap();
bit->Width = 640;
bit->Height = 480;for( int y=0 ; y<480 ; y++ ){
for( int x=0 ; x<640 ; x++ ){
bit->Canvas->Pixels[x][y] =
(int)(sqrt( x*x + y*y )) % 256 |
((int)(sqrt( (640-x)*(640-x) + y*y )) % 256) << 8 |
((int)(sqrt( (320-x)*(320-x) + y*y )) % 256) << 16;
}
}PaintBox1->Canvas->Draw( 0 , 0 , bit );
delete bit;
//時間のかかる処理の例ただ、これはあくまで小手先の技で、もし並列になにか処理をしようとしたらスレッドかタイ マー割り込みを利用した方が、プログラムの可読性が高くなり、後で機能を追加する場合 等も(比較的)簡単に行えるようになります。
Graphics::TBitmap *bit = new Graphics::TBitmap();
bit->Width = 640;
bit->Height = 480;for( int y=0 ; y<480 ; y++ ){
for( int x=0 ; x<640 ; x++ ){
Application->ProcessMessages(); // <- 追加
bit->Canvas->Pixels[x][y] =
(int)(sqrt( x*x + y*y )) % 256 |
((int)(sqrt( (640-x)*(640-x) + y*y )) % 256) << 8 |
((int)(sqrt( (320-x)*(320-x) + y*y )) % 256) << 16;
}
}PaintBox1->Canvas->Draw( 0 , 0 , bit );
delete bit;