Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Timer String Problem? (https://www.delphipraxis.net/202246-timer-string-problem.html)

gee21 12. Okt 2019 18:55

Timer String Problem?
 
Hallo

Ich wollte in meinem Programm 4 Bilder laden wenn die Maus über eine bestimmte Radiogroup fährt.
dazu habe ich folgenden Code in einem Timer um die Mausposition abzufragen und die Bilder zu laden.

Damit nun die Bilder nicht immer und immer wieder geladen werden solange der User die Mausposition NICHT verändert, wollte ich das zuletzt geladene Bild mit einem String "merken"

Leider scheint das so nicht zu klappen obwohl der string zu r1 gesetzt wird(das sehe ich im memo), werden die Bilder trotzdem immer und immer wieder geladen.... WAS MACHE ICH FALSCH? :?:

Delphi-Quellcode:
procedure TForm2.Timer2Timer(Sender: TObject);
var
selopt: string;

begin


  if selopt = 'r1' = false then if radiogroup3.Visible=true then
  if mouse.CursorPos.x>form2.Left+panel8.Left+radiogroup3.Left then
  if mouse.CursorPos.x<form2.Left+panel8.Left+radiogroup3.Left+radiogroup3.Width then
  if mouse.CursorPos.y>form2.top+panel2.top+panel8.Top+panel6.Top+radiogroup3.top+panel5.Height then
  if mouse.CursorPos.y<form2.top+panel5.Height+panel2.top+panel6.Top+panel8.Top+radiogroup3.top+radiogroup3.height then begin

  if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC1.jpg') then Image1.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC1.jpg') else image1.Picture:=nil;
  if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC1.jpg') then Image2.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC1.jpg') else image2.Picture:=nil;
  if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC2.jpg') then image3.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC2.jpg') else image3.Picture:=nil;
  if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC3.jpg') then image4.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT1_PIC3.jpg') else image4.Picture:=nil;

  selopt:='r1';

  form5.Memo1.Lines.Add(selopt);
  end;



 if selopt = 'r2' = false then if radiogroup4.Visible=true then
 if mouse.CursorPos.x>form2.Left+panel8.Left+radiogroup4.Left then
 if mouse.CursorPos.x<form2.Left+panel8.Left+radiogroup4.Left+radiogroup4.Width then
 if mouse.CursorPos.y>form2.top+panel2.top+panel8.Top+panel6.Top+radiogroup4.top+panel5.Height then
 if mouse.CursorPos.y<form2.top+panel5.Height+panel2.top+panel6.Top+panel8.Top+radiogroup4.top+radiogroup4.height then begin

 if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC1.jpg') then Image1.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC1.jpg') else image1.picture:=nil;
 if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC1.jpg') then Image2.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC1.jpg') else image2.picture:=nil;
 if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC2.jpg') then image3.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC2.jpg') else image3.picture:=nil;
 if tfile.Exists(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC3.jpg') then image4.Picture.LoadFromFile(programmpfad+'MEDIA\'+selectedid+'_OPT2_PIC3.jpg') else image4.picture:=nil;

  selopt:='r2';

  form5.Memo1.Lines.Add(selopt);
 end;

Luckie 12. Okt 2019 20:17

AW: Timer String Problem?
 
Du merkst dir nichts. selopt ist eine lokale Variable. Wenn die Prozedur durchgelaufen ist und wieder aufgerufen wird, steht da besten falls nichts drin.

gee21 12. Okt 2019 20:27

AW: Timer String Problem?
 
Zitat:

Zitat von Luckie (Beitrag 1449532)
Du merkst dir nichts. selopt ist eine lokale Variable. Wenn die Prozedur durchgelaufen ist und wieder aufgerufen wird, steht da besten falls nichts drin.

achso :) danke dir

Delphi-Laie 12. Okt 2019 21:40

AW: Timer String Problem?
 
Und nicht auf "= true" und "= false" prüfen, das ist unelegant. Besser ist einfach "if" bzw. "if not...".

Redeemer 13. Okt 2019 12:27

AW: Timer String Problem?
 
Zitat:

Zitat von Luckie (Beitrag 1449532)
Wenn die Prozedur durchgelaufen ist und wieder aufgerufen wird, steht da besten falls nichts drin.

In lokalen string-Variablen (außer dem Funktionsergebnis) steht anfangs immer nichts drin.

Luckie 13. Okt 2019 13:43

AW: Timer String Problem?
 
Bei Strings war ich mir nicht sicher, ob nicht doch eventuell Schrott drin stehen könnte. Macht aber in diesem Fall nichts, da der Inhalt nach abarbeiten der Prozedur eh verloren ist.


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:40 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz