hido yazdı:Selam.
Anlık olarak db'ye kayıt yapılırken 100%100 olarak labelda göstermek istiyorum, çok ilginç ki form caption anlık olarak değer yansırken label captionunda işlem bittikten sonra 100%100 olarak yansımakta bunu nedeni ne olabilir?
Kod: Tümünü seç
Label2.Caption := 'Kaydedildi ' + IntToStr(PLSayac * 100 div Max) + '%';
Caption := 'Kaydedildi ' + IntToStr(PLSayac * 100 div Max) + '%100';
Merhaba,
- Delphi bir ana thread içinde çalışır. Bu thread boşta (idle) olduğu zaman eğer bekleyen ekran güncellemesi varsa bunlar yapılır. Siz DB kayıt işlemini bir döngü ile yapıyorsanız, döngü bitene kadar ekran bileşenlerinde güncelleme olmaz. Bunun önüne geçmek için Application.ProseccMessages() kullanılabilir. Ancak bu durumda ekran ile ilgili bekleyen tüm değişikliklerin yapılması durumu ortaya çıkar.
- Sadece bir bileşenin ekranda değiştirilmiş bilgiyi göstermesi için Update() prosedürünü kullanabilirsiniz.
- Son olarak, performans açısından hesabı bir kere yapıp aynı bilgi ise diğer yerlere sonuç değerini atamak daha doğru olacaktır.
Aşağıdaki gibi bir kod ile sorununuzun çözülmesi gerekli diye düşünüyorum.
Kod: Tümünü seç
Label1.Caption := 'Kaydedildi ' + IntToStr(PLSayac * 100 div Max) + '%';
Label2.Caption := Label1.Caption;
Self.Caption := Label1.Caption + '%100';
Label1.Update();
Labrl2.Update();
Delphi 10.1 Update2 yardım dosyasından alıntılar aşağıdadır:
INVALIDATE: Completely repaints the control. Use Invalidate when the entire control needs to be repainted. When more than one region within the control needs repainting, Invalidate will cause the entire window to be repainted in a single pass, avoiding flicker caused by redundant repaints. There is no performance penalty for calling Invalidate multiple times before the control is actually repainted.
REFRESH: Repaints the control on the screen. Call the Refresh method to repaint the control immediately. Refresh calls the Repaint method. Use the Refresh and Repaint methods interchangeably.
REPAINT: Forces the control to repaint its image on the screen. Call Repaint to force the control to repaint its image immediately. If the ControlStyle property includes csOpaque, the control paints itself directly. Otherwise, the Repaint method calls the Invalidate method and then the Update method so that any visible portions of controls beneath the control will be repainted as well.
UPDATE: Processes any pending paint messages immediately. Call Update to force the control to be repainted before any more, possibly time-consuming, processing takes place. Use Update to provide immediate feedback to the user that cannot wait for the Windows paint message to arrive. Update does not invalidate the control, but simply forces a repaint of any regions that have already been invalidated. Call Repaint instead to invalidate the control as well.
Detaylı incelenir ise UPDATE sadece değişen yerleri güncelliyor olduğu anlaşılacaktır. Dolayısıyla performans anlamında kullanılması tercih edilebilir. Diğer taraftan titreme sorunu yaşanıyor ise INVALIDATE kullanılması bu sorunu minimuma indirmeye yardımcı olabilir. INVALIDATE ile birlikte DoubleBuffer kullanılabilir. Ancak DoubleBuffer theme kullanılan uygulamalarda sorunlara yol açtığı gözlemlenmiştir.