Recent

Author Topic: Form Close don't close form  (Read 1381 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 295
Form Close don't close form
« on: January 05, 2022, 01:45:58 am »
Hi I have this problem and i don't understand what is wrong from main form a call a new form but when click on close button don't close still active

this code called to other form
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ToolButton2Click(Sender: TObject);
  2. begin
  3.   if not Assigned(FormOpenCia) then begin
  4.      Application.CreateForm(TFormOpenCia, FormOpenCia );
  5.   end;
  6.   FormOpenCia.ShowModal;
  7. end;    
  8.  

and this code form
Code: Pascal  [Select][+][-]
  1. unit fopencia;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, db, sqldb, Forms, Controls, Graphics, Dialogs, DBGrids,
  9.   Buttons, DateUtils;
  10.   function updatebalance():boolean;
  11. type
  12.  
  13.   { TFormOpenCia }
  14.  
  15.   TFormOpenCia = class(TForm)
  16.     BtnOk: TBitBtn;
  17.     BtnClose: TBitBtn;
  18.     DBGCias: TDBGrid;
  19.     DSCias: TDataSource;
  20.     SQLQCias: TSQLQuery;
  21.     SQLQCiasCKBIT: TWideStringField;
  22.     SQLQCiasCOMPLETE: TLongintField;
  23.     SQLQCiasDEFHRS: TBCDField;
  24.     SQLQCiasDPOLICY: TLongintField;
  25.     SQLQCiasEROLL: TWideStringField;
  26.     SQLQCiasFCADD1: TWideStringField;
  27.     SQLQCiasFCADD2: TWideStringField;
  28.     SQLQCiasFCCITY: TWideStringField;
  29.     SQLQCiasFCKEY: TLongintField;
  30.     SQLQCiasFCNAME: TWideStringField;
  31.     SQLQCiasFCOTHER: TWideStringField;
  32.     SQLQCiasFCSTATE: TWideStringField;
  33.     SQLQCiasFCZIPCODE: TWideStringField;
  34.     SQLQCiasLP_EDATE: TDateField;
  35.     SQLQCiasLP_SDATE: TDateField;
  36.     procedure BtnOkClick(Sender: TObject);
  37.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  38.     procedure FormShow(Sender: TObject);
  39.   private
  40.  
  41.   public
  42.  
  43.   end;
  44.  
  45. var
  46.   FormOpenCia: TFormOpenCia;
  47.  
  48. implementation
  49.  uses Fmain;
  50. {$R *.lfm}
  51.  
  52. { TFormOpenCia }
  53.  
  54. procedure TFormOpenCia.BtnOkClick(Sender: TObject);
  55.  
  56. begin
  57.  
  58.   FormMain.Caption := 'Company :'+SQLQCias.FieldByName('fcname').AsString;
  59.   FormMain.idcia:= SQLQCias.FieldByName('fckey').AsString ;
  60.   FormMain.namecia:= SQLQCias.FieldByName('fcname').AsString;
  61.   FormMain.Hrs:= SQLQCias.FieldByName('defhrs').AsInteger ;
  62.   FormMain.Policy:= SQLQCias.FieldByName('dpolicy').AsInteger ;
  63.   FormMain.SQLQFold.ParamByName('pidcia').AsString:= FormMain.idcia;
  64.   FormMain.StartPeriod:= SQLQCias.FieldByName('lp_sdate').AsDateTime;
  65.   FormMain.EndPeriod:= SQLQCias.FieldByName('lp_edate').AsDateTime;
  66.   FormMain.StatusBar1.Panels[0].Text:='Working Period From :'+FormatDateTime('mm-dd-yyyy',FormMain.StartPeriod) +' End Period :'+FormatDateTime('mm-dd-yyyy',FormMain.EndPeriod) ;
  67.   FormMain.SQLQFold.Open;
  68.   FormMain.SQLQFold.First;
  69.  
  70.   FormMain.SQLQVacd.ParamByName('folderkey').AsString:=FormMain.SQLQFold.FieldByName('folderkey').AsString  ;
  71.   if( monthof(FormMain.Calendarlite1.Date) < 10) then begin
  72.      FormMain.SQLQVacd.ParamByName('month').AsString:= '0'+ inttostr( monthof(FormMain.Calendarlite1.Date)); ;
  73.   end else begin
  74.    FormMain.SQLQVacd.ParamByName('month').AsString   :=  inttostr( monthof(FormMain.Calendarlite1.Date));
  75.   end;
  76.   FormMain.SQLQVacd.ParamByName('pfc').AsString:=FormMain.idcia  ;
  77.   FormMain.SQLQVacd.Open;
  78.   if not FormMain.SQLQFold.EOF  then begin
  79.        FormMain.MenuMigrate.Enabled:=false;
  80.    end else begin
  81.        FormMain.MenuMigrate.Enabled:=true;
  82.    end;
  83.    if FormMain.EndPeriod < Date then begin
  84.       FormMain.MenuItem15.Enabled:=true;
  85.    end else begin
  86.       FormMain.MenuItem15.Enabled:=false;
  87.    end;
  88.  
  89.    FormMain.MenuItemBkp.Enabled:=false;
  90.    FormMain.CalendarLite1MonthChange(FormMain.CalendarLite1);
  91.  
  92.    FormMain.AutoPanel1.Visible:=true;
  93.    FormMain.TCFold.PageIndex:=0;
  94.    FormMain.TCFold.Tabs.Clear;
  95.    if( not FormMain.SQLQFold.eof) then begin
  96.      FormMain.RxDBGrid1.Refresh;
  97.      FormMain.TCFold.Tabs.Add(FormMain.SQLQFold.FieldByName('Lname').AsString +' '+FormMain.SQLQFold.FieldByName('mname').AsString+FormMain.SQLQFold.FieldByName('fname').AsString );
  98.      FormMain.CalcBalance();
  99.    end;
  100.    FormMain.ToolButton3.Enabled:=true;
  101.    FormMain.TBNewFld.Enabled:=true;
  102.    FormMain.TBFoldEdit.Enabled:=true;
  103.    FormMain.TBFoldDel.Enabled:=true;
  104.    FormMain.Btnnew.Enabled:=true;
  105.    FormMain.BtnEdit.Enabled:=true;
  106.    FormMain.BtnDel.Enabled:=true;
  107.  
  108.    SQLQCias.Close;
  109.    FormMain.Refresh;
  110.    FormMain.RxDBGrid1.SetFocus;
  111.    FormOpenCia.Close;
  112. end;
  113.  
  114. procedure TFormOpenCia.FormClose(Sender: TObject; var CloseAction: TCloseAction
  115.   );
  116. begin
  117.    CloseAction := CaFree;
  118.    SQLQCias.Close;
  119.    FormOpenCia:=nil;
  120. end;
  121.  
  122. procedure TFormOpenCia.FormShow(Sender: TObject);
  123. begin
  124.   if SQLQCias.Active = false then begin
  125.      SQLQCias.Open;
  126.   end else begin
  127.      SQLQCias.Close;
  128.      SQLQCias.Open;
  129.   end;
  130. end;
  131.  
  132. Function updatebalance():boolean;
  133. begin
  134.  
  135. // FormMain.SQLQVacd.SQL.Text:='select * from lvlv where folderid=:fld and fc :=pidcia';
  136.   FormMain.SQLQVacd.ParamByName('folderkey').AsString:=FormMain.SQLQFold.FieldByName('folderkey').AsString  ;
  137.    FormMain.SQLQVacd.ParamByName('pfc').AsString:=FormMain.idcia  ;
  138.     if( monthof(FormMain.Calendarlite1.Date) < 10) then begin
  139.      FormMain.SQLQVacd.ParamByName('month').AsString:= '0'+ inttostr( monthof(FormMain.Calendarlite1.Date)); ;
  140.   end else begin
  141.    FormMain.SQLQVacd.ParamByName('month').AsString   :=  inttostr( monthof(FormMain.Calendarlite1.Date));
  142.   end;
  143.   FormMain.SQLQVacd.Open;
  144.   FormMain.AutoPanel1.Visible:=true;
  145.   FormMain.TCFold.PageIndex:=0;
  146.   FormMain.TCFold.Tabs.Clear;
  147.   FormMain.TCFold.Height:=FormMain.Height-70 ;
  148.   FormMain.TCFold.Width:=FormMain.Width-360 ;
  149.   FormMain.TCFold.Tabs.Add(FormMain.SQLQFold.FieldByName('Lname').AsString +' '+FormMain.SQLQFold.FieldByName('mname').AsString+FormMain.SQLQFold.FieldByName('fname').AsString );
  150.   FormMain.SQLQVacd.First;
  151.   FormMain.VacaUsd :=0;
  152.   FormMain.SicUsd :=0;
  153.   FormMain.admiusd:=0;
  154.   FormMain.compusd:=0;
  155.   FormMain.otherusd:=0;
  156.   FormMain.fmlausd:=0;
  157.   while not FormMain.SQLQVacd.EOF do begin
  158.      if (FormMain.SQLQVacd.FieldByName('lvdate').AsString <> '') then begin
  159.         if( MonthOf(StrToDate(FormMain.SQLQVacd.FieldByName('lvdate').AssTRING)) = Monthof( FormMain.CalendarLite1.Date)) then begin
  160.           FormMain.CalendarLite1.AddSelectedDate( StrToDate(FormMain.SQLQVacd.FieldByName('lvdate').AsString));
  161.         end;
  162.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='Vacation') then begin
  163.             FormMain.VacaUsd := FormMain.vacausd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  164.         end;
  165.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='Sick') then begin
  166.             FormMain.SicUsd := FormMain.sicusd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  167.         end;
  168.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='Administrative') then begin
  169.             FormMain.AdmiUsd := FormMain.admiusd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  170.         end;
  171.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='UnAuthorized') then begin
  172.             FormMain.UnathUsd := FormMain.unathusd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  173.         end;
  174.  
  175.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='Compensation') then begin
  176.             FormMain.CompUsd := FormMain.compusd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  177.         end;
  178.  
  179.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='Other') then begin
  180.             FormMain.otherUsd := FormMain.otherusd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  181.         end;
  182.  
  183.         if( Trim(FormMain.SQLQVacd.FieldByName('type').AsString) ='FMLA') then begin
  184.             FormMain.fmlaUsd := FormMain.fmlausd+FormMain.SQLQVacd.FieldByName('hrs').AsInteger;
  185.         end;
  186.      end;
  187.      FormMain.SQLQVacd.Next;
  188.   end;
  189.    FormMain.VacEr.Text:= FormMain.SQLQFold.FieldByName('El_VACA').AsString;
  190.    FormMain.VacFw.Text:= FormMain.SQLQFold.FieldByName('FW_VACA').AsString;
  191.    FormMain.SickEr.Text:= FormMain.SQLQFold.FieldByName('El_SICK').AsString;
  192.    FormMain.sickFw.Text:= FormMain.SQLQFold.FieldByName('FW_SICK').AsString;
  193.    FormMain.adEr.Text:= FormMain.SQLQFold.FieldByName('EL_ADMIN').AsString;
  194.    FormMain.adFW.Text:= FormMain.SQLQFold.FieldByName('FW_ADMIN').AsString;
  195.    FormMain.unEr.Text:= FormMain.SQLQFold.FieldByName('EL_UNAUTH').AsString;
  196.    FormMain.unFW.Text:= FormMain.SQLQFold.FieldByName('FW_UNAUTH').AsString;
  197.    FormMain.ComEr.Text:= FormMain.SQLQFold.FieldByName('EL_COMP').AsString;
  198.    FormMain.ComFW.Text:= FormMain.SQLQFold.FieldByName('FW_COMP').AsString;
  199.    FormMain.othEr.Text:= FormMain.SQLQFold.FieldByName('EL_OTHER').AsString;
  200.    FormMain.othFW.Text:= FormMain.SQLQFold.FieldByName('FW_OTHER').AsString;
  201.    FormMain.fmlEr.Text:= FormMain.SQLQFold.FieldByName('EL_FMLA').AsString;
  202.    FormMain.fmlFW.Text:= FormMain.SQLQFold.FieldByName('FW_FMLA').AsString;
  203.  
  204.    FormMain.VacUsd.Text:= InttoStr(FormMain.vacausd);
  205.    FormMain.SickUsd.Text:= InttoStr(FormMain.Sicusd);
  206.    FormMain.admusd.Text  := InttoStr(FormMain.admiusd);
  207.    FormMain.unusd.Text  := InttoStr(FormMain.unathusd);
  208.    FormMain.comusd.Text  := InttoStr(FormMain.compusd);
  209.    FormMain.othusd.Text  := InttoStr(FormMain.otherusd);
  210.    FormMain.FMLusd.Text  := InttoStr(FormMain.FMLAusd);
  211.  
  212.    FormMain.VacBlc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_VACA').AsString)  - StrToInt(FormMain.VacUsd.Text));
  213.    FormMain.sickBlc.Text := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_SICK').AsString)  - StrToInt(FormMain.SickUsd.Text));
  214.    FormMain.adblc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_ADMIN').AsString) - StrToInt(FormMain.ADMUsd.Text));
  215.    FormMain.unblc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_UNAUTH').AsString) - StrToInt(FormMain.UnUsd.Text));
  216.    FormMain.comblc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_COMP').AsString) - StrToInt(FormMain.ComUsd.Text));
  217.    FormMain.othblc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_OTHER').AsString) - StrToInt(FormMain.OthUsd.Text));
  218.    FormMain.fmlblc.Text  := IntToStr(StrToInt(FormMain.SQLQFold.FieldByName('EL_FMLA').AsString) - StrToInt(FormMain.fmlUsd.Text));
  219.  
  220.  
  221. end;
  222. end.
  223.  
  224.  
  225.  

 

TinyPortal © 2005-2018