Recent

Author Topic: .release works, .acquire doesn't. (resetting forms)  (Read 301 times)

waituntilthis

  • New Member
  • *
  • Posts: 24
.release works, .acquire doesn't. (resetting forms)
« on: October 11, 2019, 11:18:46 am »
hi all, i'm making a program in wich you use buttons to close and open forms. recently, I needed one of the forms to go back to its core values everytime it opened up. (moving objects had to return to their start position and timers needed to be reset) I got it to work with. free, but later on I had to remove that. I still needed the form to 'reset' so I used .release, so that the form closes without giving me a SIGSEGV. thing is, after I .release a form, I can't get it back! I tried to open the forms with .acquire but my ide doesn't recognize that. i'm on windows, and my IDE is v1.8.4. the code of form8 is below.

Code: Pascal  [Select][+][-]
  1. procedure TForm8.Timer1Timer(Sender: TObject);
  2. var
  3.   x, g: integer;
  4. begin
  5.   ded:=false;
  6.   if (you.BoundsRect.IntersectsWith(back.BoundsRect)) then
  7.   begin
  8.     form8.release;
  9.     form6.show;
  10.     direction:= -1;
  11.     form6.label1.caption:='you fled the castle';
  12.   end;
  13.   if (you.BoundsRect.IntersectsWith(forward.BoundsRect)) then
  14.   begin
  15.     form8.release;
  16.     form6.show;
  17.     direction:= -1;
  18.   end;
  19.   for x:=low(wall) to high(wall) do
  20.   begin
  21.     for g:=low(knight) to high(knight) do
  22.     begin
  23.       if(knight[g].BoundsRect.IntersectsWith(wall[x].BoundsRect)) then
  24.       begin
  25.         ch_direction(g);
  26.       end;
  27.  
  28.       if(you.BoundsRect.IntersectsWith(knight[g].BoundsRect)) then
  29.       begin
  30.         form8.release;
  31.         form6.Show;
  32.         ded:=true;
  33.         direction:= -1;
  34.       end;
  35.     end;
  36.  
  37.     if(you.BoundsRect.IntersectsWith(wall[x].BoundsRect)) then
  38.     begin
  39.       form8.release;
  40.       form6.Show;
  41.       ded:=true;
  42.       direction:= -1;
  43.     end;
  44.   end;
  45.  
  46. end;

and here is the code for the retrieval of the form. (form6)

Code: Pascal  [Select][+][-]
  1. procedure TForm6.Button3Click(Sender: TObject);
  2. begin
  3.   form1.hunger();
  4.   if button3.caption='approach' then
  5.   begin
  6.   label2.caption:='the guard draws his sword';
  7.   label3.visible:=true;
  8.   label4.visible:=true;
  9.   button3.caption:='RUN';
  10.   end
  11.   else if (button3.caption='RUN') or (button3.caption='try again') then
  12.   begin
  13.   form8.show;
  14.   form6.hide;
  15.   form8.timer2.enabled:=true;
  16.   end;
  17. end;

can anyone tell me how to reset forms better? i'm at a loss.

waituntilthis

  • New Member
  • *
  • Posts: 24
Re: .release works, .acquire doesn't. (resetting forms)
« Reply #1 on: October 11, 2019, 02:27:03 pm »
if anyone was interested in replying, I have removed .release entirely and just resetted the entire form by returning everything to their start value, that sorta does the trick.

Thaddy

  • Hero Member
  • *****
  • Posts: 10271
Re: .release works, .acquire doesn't. (resetting forms)
« Reply #2 on: October 11, 2019, 03:22:30 pm »
release has two different meanings: if you call release on the form it is free'd: no longer valid.
Release on a locked resource (Like in TMultipleReadSingleWriteSynchronizer) releases a locked part of memory, so it can be used by other threads. Acquire has only meaning for the latter.

What you were doing is destroying a form and then asking it to show......
I am more like donkey than shrek

 

TinyPortal © 2005-2018