Recent

Author Topic: Dialog Dispose, Done result in AV  (Read 3091 times)

paule32

  • Full Member
  • ***
  • Posts: 248
Dialog Dispose, Done result in AV
« on: April 03, 2024, 06:20:56 pm »
Hello,
I have to following Code Snippet of the FreeVision Port for the Windows 10 Command Console...
how can I check, if cmStopAndSave is pressed ?
I tried:

Code: Pascal  [Select][+][-]
  1. dummy := desktop^.ExecView(PrimeDialog);
  2. if dummy = cmStopAndSave then begin
  3. // close the dialog - but this would not working:
  4. // Dispose(PrimeDialog, Done);
  5. //
  6. // when I call without dummy, also: desktop^.insert(PrimeDialog); the result is a AV - Access Violation.
  7. end;

So, how can I close/remove the dialog ?

Code: Pascal  [Select][+][-]
  1. procedure TPrimeApp.doPrimeDialog;
  2. var
  3.   R: Objects.TRect;
  4.   dummy: Word;
  5.   line_start, line_end, cindex, cforce: PView;
  6. begin
  7.   R.Assign(0,0,72,16);
  8.   R.Move(4,3);
  9.  
  10.   PrimeDialog := New(PDialog, Init(R, 'Prime finder Dialog'));
  11.   with PrimeDialog^ do begin
  12.     // text 1
  13.     R.Assign(2,1, 43,2);
  14.     Insert(New(PStaticText, Init(R, 'Start Prime:')));
  15.    
  16.     // text 2
  17.     R.Assign(2,4, 43,5);
  18.     Insert(New(PStaticText, Init(R, 'End Prime:')));
  19.    
  20.     // input line: prime start
  21.     R.Assign(2,2, 64,3);
  22.     line_start := New(PInputLine,Init(R, 250));
  23.     insert(line_start);
  24.    
  25.     // input line: prime end
  26.     R.Assign(2,5, 64,6);
  27.     line_end := New(PInputLine,Init(R, 250));
  28.     insert(line_end);
  29.  
  30.     // checkbox: parameter
  31.     R.Assign( 2,7, 23, 8); Insert(New(PStaticText, Init(R, 'Parameter 1:')));
  32.     R.Assign(26,7, 47, 8); Insert(New(PStaticText, Init(R, 'Parameter 2:')));
  33.    
  34.     R.Assign( 2,8, 23, 9); cindex := New(PCheckBoxes, Init(R, NewSItem('~o~nly one check', nil)));
  35.     R.Assign(26,8, 47, 9); cforce := New(PCheckBoxes, Init(R, NewSItem('~f~orce start'   , nil)));
  36.     Insert(cindex);
  37.     Insert(cforce);
  38.    
  39.     // text: index
  40.     R.Assign(2,10, 42,11); Insert(New(PStaticText, Init(R, 'Index:')));
  41.     R.Assign(2,11, 42,12); Insert(New(PStaticText, Init(R, 'Prime:')));
  42.    
  43.     // text: prime
  44.     R.Assign(10,10, 42,11); Insert(New(PStaticText, Init(R, '1')));
  45.     R.Assign(10,11, 42,12); Insert(New(PStaticText, Init(R, '2')));
  46.    
  47.     // button: cancel
  48.     R.Assign(2,13, 24,15);
  49.     Insert(New(PButton, Init(R, '~C~ancel Search', cmCancelSearch, bfDefault)));
  50.    
  51.     // button: load data
  52.     R.Assign(26,13, 46,15);
  53.     Insert(New(PButton, Init(R, '~L~oad Data', cmStopAndLoad, bfNormal)));
  54.    
  55.     // button: save data
  56.     R.Assign(48,13, 69,15);
  57.     Insert(New(PButton, Init(R, '~S~top and saves', cmStopAndSave, bfNormal)));
  58.   end;
  59.  
  60.   if ValidView(PrimeDialog) <> nil then begin
  61.     desktop^.insert(PrimeDialog);
  62.   end;
  63. end;

paule32

  • Full Member
  • ***
  • Posts: 248
Re: Dialog Dispose, Done result in AV
« Reply #1 on: April 03, 2024, 09:42:16 pm »
okay, I have it done.

I had to do subclass the TDialog class.
Then, in HandleEvent, I could create the dialog by dialogobj.Init;

In the Event handler of the dialogobj, I don't add code ClearEvent, so the memory points to nirvana...

 

TinyPortal © 2005-2018