Bladeren bron

Protect resource release for multiple objects by using try..finally x.free

Reinier Olislagers 11 jaren geleden
bovenliggende
commit
fb6f8f1b25
18 gewijzigde bestanden met toevoegingen van 1972 en 1890 verwijderingen
  1. 26 24
      backuprestore.pas
  2. 504 507
      comparison.pas
  3. 35 31
      copytable.pas
  4. 45 42
      dbinfo.pas
  5. 572 557
      main.pas
  6. 7 4
      newconstraint.pas
  7. 24 21
      newgen.pas
  8. 20 19
      newtable.pas
  9. 42 44
      permissionmanage.lfm
  10. 65 63
      permissionmanage.lrs
  11. 77 68
      permissionmanage.pas
  12. 77 76
      querywindow.pas
  13. 263 238
      scriptdb.pas
  14. 22 19
      sqlhistory.pas
  15. 85 76
      tablemanage.pas
  16. 20 20
      update.lfm
  17. 21 19
      update.lrs
  18. 67 62
      update.pas

+ 26 - 24
backuprestore.pas

@@ -96,33 +96,35 @@ var
   ADatabase: string;
 begin
   FireBirdServices:= TFirebirdServices.Create;
-  FireBirdServices.VerboseOutput:= True;
-  meLog.Clear;
-  with FireBirdServices do
-  begin
-    HostName:= edHost.Text;
-    DBName:= edTargetDatabase.Text;
-    UserName := edUserName.Text;
-    Password := edPassword.Text;
-    BkpName := Trim(edBackup.Text);
-
-    try
-      AttachService;
-
-      if cbOperation.ItemIndex = 0 then
-        StartBackup
-      else
-        StartRestore;
-
-      while ServiceQuery(Res) do
-        meLog.Lines.Add(Res);
-    finally
-      DetachService;
+  try
+    FireBirdServices.VerboseOutput:= True;
+    meLog.Clear;
+    with FireBirdServices do
+    begin
+      HostName:= edHost.Text;
+      DBName:= edTargetDatabase.Text;
+      UserName := edUserName.Text;
+      Password := edPassword.Text;
+      BkpName := Trim(edBackup.Text);
+
+      try
+        AttachService;
+
+        if cbOperation.ItemIndex = 0 then
+          StartBackup
+        else
+          StartRestore;
+
+        while ServiceQuery(Res) do
+          meLog.Lines.Add(Res);
+      finally
+        DetachService;
+      end;
+      meLog.Lines.Add('');
     end;
-    meLog.Lines.Add('');
+  finally
     FireBirdServices.Free;
   end;
-
 end;
 
 

File diff suppressed because it is too large
+ 504 - 507
comparison.pas


+ 35 - 31
copytable.pas

@@ -67,9 +67,12 @@ var
   Line: string;
 begin
   List:= TStringList.Create;
-  fmMain.GetFields(fSourceIndex, cbSourceTable.Text, List);
-  Line:= List.CommaText;
-  List.Free;
+  try
+    fmMain.GetFields(fSourceIndex, cbSourceTable.Text, List);
+    Line:= List.CommaText;
+  finally
+    List.Free;
+  end;
   syScript.Lines.Text:= 'select ' + Line;
   syScript.Lines.Add(' from ' + cbSourceTable.Text);
 
@@ -130,37 +133,38 @@ begin
     end;
 
     SQLTarget:= TSQLQuery.Create(nil);
-    SQLTarget.DataBase:= IBConnection;
-    SQLTarget.Transaction:= SQLTrans;
-    SQLTarget.SQL.Text:= Statement;
-
-    // Start copy
     try
-      dmSysTables.sqQuery.First;
-      Num:= 0;
-      with dmSysTables.sqQuery do
-      while not EOF do
-      begin
-        for i:= 0 to Fields.Count - 1 do
-          SQLTarget.Params.ParamByName(Fields[i].FieldName).Value:= Fields[i].Value;
-        SQLTarget.ExecSQL;
-        Inc(Num);
-        Next;
+      SQLTarget.DataBase:= IBConnection;
+      SQLTarget.Transaction:= SQLTrans;
+      SQLTarget.SQL.Text:= Statement;
+
+      // Start copy
+      try
+        dmSysTables.sqQuery.First;
+        Num:= 0;
+        with dmSysTables.sqQuery do
+        while not EOF do
+        begin
+          for i:= 0 to Fields.Count - 1 do
+            SQLTarget.Params.ParamByName(Fields[i].FieldName).Value:= Fields[i].Value;
+          SQLTarget.ExecSQL;
+          Inc(Num);
+          Next;
+        end;
+        SQLTrans.Commit;
+        ShowMessage(IntToStr(Num) + ' record(s) has been copied' + #10 + 'Don''t forget to set the Generator to the new value, ' +
+          'if it does exists');
+        dmSysTables.sqQuery.Close;
+        Close;
+      except
+        on e: exception do
+        begin
+          MessageDlg('Error while copy: ' + e.Message, mtError, [mbOk], 0);
+          SQLTrans.Rollback;
+        end;
       end;
-      SQLTrans.Commit;
-      ShowMessage(IntToStr(Num) + ' record(s) has been copied' + #10 + 'Don''t forget to set the Generator to the new value, ' +
-        'if it does exists');
-      dmSysTables.sqQuery.Close;
+    finally
       SQLTarget.Free;
-      Close;
-
-    except
-      on e: exception do
-      begin
-        MessageDlg('Error while copy: ' + e.Message, mtError, [mbOk], 0);
-        SQLTrans.Rollback;
-        SQLTarget.Free;
-      end;
     end;
   end;
 

+ 45 - 42
dbinfo.pas

@@ -96,52 +96,55 @@ var
 begin
   fdbIndex:= dbIndex;
   ProcessList:= TStringList.Create;
-
-  // Read database info
-  if dmSysTables.GetDatabaseInfo(dbIndex, dbName, ACharSet, CreationDate, ServerTime,
-    MajorVer, MinorVer, Pages, PageSize, ProcessList, ErrorMsg) then
-  begin
-    edName.Text:= dbName;
-    edODSVer.Text:= IntToStr(MajorVer) + '.' + IntToStr(MinorVer);
-    edCharset.Text:= ACharSet;
-    edCreationDate.Text:= CreationDate;
-    edPageSize.Text:= IntToStr(PageSize);
-    edConnections.Text:= IntToStr(ProcessList.Count);
-    dbSize:= Pages * PageSize;
-
-    // Display database size in readable format
-    if dbSize > (1024*1024*1024) then
-    begin
-      dbSize:= ((dbSize / 1024) / 1024) / 1024;
-      AType:= 'Giga bytes';
-    end
-    else
-    if dbSize > (1024*1024) then
-    begin
-      dbSize:= ((dbSize / 1024) / 1024);
-      AType:= 'Mega bytes';
-    end
-    else
-    if dbSize > 1024 then
+  try
+    // Read database info
+    if dmSysTables.GetDatabaseInfo(dbIndex, dbName, ACharSet, CreationDate, ServerTime,
+      MajorVer, MinorVer, Pages, PageSize, ProcessList, ErrorMsg) then
     begin
-      dbSize:= (dbSize / 1024);
-      AType:= 'Kilo bytes';
+      edName.Text:= dbName;
+      edODSVer.Text:= IntToStr(MajorVer) + '.' + IntToStr(MinorVer);
+      edCharset.Text:= ACharSet;
+      edCreationDate.Text:= CreationDate;
+      edPageSize.Text:= IntToStr(PageSize);
+      edConnections.Text:= IntToStr(ProcessList.Count);
+      dbSize:= Pages * PageSize;
+
+      // Display database size in readable format
+      if dbSize > (1024*1024*1024) then
+      begin
+        dbSize:= ((dbSize / 1024) / 1024) / 1024;
+        AType:= 'Giga bytes';
+      end
+      else
+      if dbSize > (1024*1024) then
+      begin
+        dbSize:= ((dbSize / 1024) / 1024);
+        AType:= 'Mega bytes';
+      end
+      else
+      if dbSize > 1024 then
+      begin
+        dbSize:= (dbSize / 1024);
+        AType:= 'Kilo bytes';
+      end
+      else
+      begin
+        AType:= 'Bytes';
+      end;
+
+      edDBSize.Text:= Format('%3.1n %s', [dbSize, AType]);
+      fmDBInfo.edServerTime.Text:= ServerTime;
+      meClients.Lines.Text:= ProcessList.Text;
+      meClients.Lines.Insert(0, '');
+      Show;
     end
     else
-    begin
-      AType:= 'Bytes';
-    end;
-
-    edDBSize.Text:= Format('%3.1n %s', [dbSize, AType]);
-    fmDBInfo.edServerTime.Text:= ServerTime;
-    meClients.Lines.Text:= ProcessList.Text;
-    meClients.Lines.Insert(0, '');
+      ShowMessage('Unable to get database information' + LineEnding +
+        ErrorMsg);
+  finally
     ProcessList.Free;
-    Show;
-  end
-  else
-    ShowMessage('Unable to get database information' + LineEnding +
-      ErrorMsg);
+  end;
+
 end;
 
 

File diff suppressed because it is too large
+ 572 - 557
main.pas


+ 7 - 4
newconstraint.pas

@@ -55,10 +55,13 @@ var
 begin
   // Get foriegn table fields
   FieldsList:= TStringList.Create;
-  fmMain.GetFields(DatabaseIndex, cbTables.Text, FieldsList);
-  clxForFields.Clear;
-  clxForFields.Items.AddStrings(FieldsList);
-  FieldsList.Free;
+  try
+    fmMain.GetFields(DatabaseIndex, cbTables.Text, FieldsList);
+    clxForFields.Clear;
+    clxForFields.Items.AddStrings(FieldsList);
+  finally
+    FieldsList.Free;
+  end;
   fmMain.SQLQuery1.Close;
 end;
 

+ 24 - 21
newgen.pas

@@ -54,30 +54,33 @@ begin
   begin
     Valid:= True;
     List:= TStringList.Create;
-    List.Add('create generator ' + edGenName.Text + ';');
-    if cxTrigger.Checked then
-    begin
-      Valid:= False;
-      if (cbTables.ItemIndex = -1) or (cbFields.ItemIndex = -1) then
-        MessageDlg('You should select a table and a field', mtError, [mbOk], 0)
-      else
-      if Trim(edGenName.Text) = '' then
-        MessageDlg('You should enter generator name', mtError, [mbOK], 0)
-      else
+    try
+      List.Add('create generator ' + edGenName.Text + ';');
+      if cxTrigger.Checked then
       begin
-        List.Add('CREATE TRIGGER ' + Trim(edGenName.Text) + ' FOR ' + cbTables.Text);
-        List.Add('ACTIVE BEFORE INSERT POSITION 0 ');
-        List.Add('AS BEGIN ');
-        List.Add('IF (NEW.' + cbFields.Text + ' IS NULL OR NEW.' + cbFields.Text + ' = 0) THEN ');
-        List.Add('  NEW.' + cbFields.Text + ' = GEN_ID(' + edGenName.Text + ', 1);');
-        List.Add('END;');
-        Valid:= True;
-      end;
+        Valid:= False;
+        if (cbTables.ItemIndex = -1) or (cbFields.ItemIndex = -1) then
+          MessageDlg('You should select a table and a field', mtError, [mbOk], 0)
+        else
+        if Trim(edGenName.Text) = '' then
+          MessageDlg('You should enter generator name', mtError, [mbOK], 0)
+        else
+        begin
+          List.Add('CREATE TRIGGER ' + Trim(edGenName.Text) + ' FOR ' + cbTables.Text);
+          List.Add('ACTIVE BEFORE INSERT POSITION 0 ');
+          List.Add('AS BEGIN ');
+          List.Add('IF (NEW.' + cbFields.Text + ' IS NULL OR NEW.' + cbFields.Text + ' = 0) THEN ');
+          List.Add('  NEW.' + cbFields.Text + ' = GEN_ID(' + edGenName.Text + ', 1);');
+          List.Add('END;');
+          Valid:= True;
+        end;
 
+      end;
+      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Create Generator: ' + edGenName.Text, List.Text);
+      Close;
+    finally
+      List.Free;
     end;
-    fmMain.ShowCompleteQueryWindow(fdbIndex, 'Create Generator: ' + edGenName.Text, List.Text);
-    Close;
-    List.Free;
   end
   else
     MessageDlg('You should write Generator name', mtError, [mbOK], 0);

+ 20 - 19
newtable.pas

@@ -275,27 +275,28 @@ begin
   if Validate then
   begin
     List:= TStringList.Create;
-    List.Text:= GenerateCreateSQL(KeyField, GeneratorName);
-    if cxCreateGen.Checked then
-    begin;
-      List.Add('');
-      List.Add('-- Generator');
-      List.Add('create generator ' + GeneratorName + ';');
-
-      List.Add('');
-      List.Add('-- Trigger');
-      List.Add('CREATE TRIGGER ' + GeneratorName + ' FOR ' + edNewTable.Text);
-      List.Add('ACTIVE BEFORE INSERT POSITION 0 ');
-      List.Add('AS BEGIN ');
-      List.Add('IF (NEW.' + KeyField + ' IS NULL OR NEW.' + KeyField + ' = 0) THEN ');
-      List.Add('  NEW.' + KeyField + ' = GEN_ID(' + GeneratorName + ', 1);');
-      List.Add('END;');
+    try
+      List.Text:= GenerateCreateSQL(KeyField, GeneratorName);
+      if cxCreateGen.Checked then
+      begin;
+        List.Add('');
+        List.Add('-- Generator');
+        List.Add('create generator ' + GeneratorName + ';');
+
+        List.Add('');
+        List.Add('-- Trigger');
+        List.Add('CREATE TRIGGER ' + GeneratorName + ' FOR ' + edNewTable.Text);
+        List.Add('ACTIVE BEFORE INSERT POSITION 0 ');
+        List.Add('AS BEGIN ');
+        List.Add('IF (NEW.' + KeyField + ' IS NULL OR NEW.' + KeyField + ' = 0) THEN ');
+        List.Add('  NEW.' + KeyField + ' = GEN_ID(' + GeneratorName + ', 1);');
+        List.Add('END;');
+      end;
+      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Create New Table: ' + edNewTable.Text, List.Text);
+    finally
+      List.Free;
     end;
-
-    fmMain.ShowCompleteQueryWindow(fdbIndex, 'Create New Table: ' + edNewTable.Text, List.Text);
-    List.Free;
     bbCloseClick(nil);
-
   end;
 end;
 

+ 42 - 44
permissionmanage.lfm

@@ -8,7 +8,7 @@ object fmPermissionManage: TfmPermissionManage
   ClientWidth = 518
   OnClose = FormClose
   Position = poScreenCenter
-  LCLVersion = '1.0.4.0'
+  LCLVersion = '1.2.0.3'
   object PageControl1: TPageControl
     Left = 0
     Height = 368
@@ -20,86 +20,86 @@ object fmPermissionManage: TfmPermissionManage
     TabOrder = 0
     object tsTables: TTabSheet
       Caption = 'Tables'
-      ClientHeight = 337
-      ClientWidth = 492
+      ClientHeight = 342
+      ClientWidth = 488
       object Label1: TLabel
         Left = 14
-        Height = 18
+        Height = 13
         Top = 11
-        Width = 67
+        Width = 47
         Caption = 'User/Role'
         ParentColor = False
       end
       object Label2: TLabel
         Left = 14
-        Height = 18
+        Height = 13
         Top = 95
-        Width = 37
+        Width = 26
         Caption = 'Table'
         ParentColor = False
       end
       object cbTables: TComboBox
         Left = 18
-        Height = 31
+        Height = 21
         Top = 124
         Width = 236
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbTablesChange
         Style = csDropDownList
         TabOrder = 0
       end
       object Label3: TLabel
         Left = 310
-        Height = 18
+        Height = 13
         Top = 10
-        Width = 83
+        Width = 55
         Caption = 'Permissions'
         ParentColor = False
       end
       object cxSelect: TCheckBox
         Left = 317
-        Height = 24
+        Height = 17
         Top = 86
-        Width = 67
+        Width = 49
         Caption = 'Select'
         TabOrder = 1
       end
       object cxInsert: TCheckBox
         Left = 318
-        Height = 24
+        Height = 17
         Top = 138
-        Width = 65
+        Width = 49
         Caption = 'Insert'
         TabOrder = 2
       end
       object cxUpdate: TCheckBox
         Left = 317
-        Height = 24
+        Height = 17
         Top = 183
-        Width = 76
+        Width = 55
         Caption = 'Update'
         TabOrder = 3
       end
       object cxDelete: TCheckBox
         Left = 317
-        Height = 24
+        Height = 17
         Top = 236
-        Width = 70
+        Width = 51
         Caption = 'Delete'
         TabOrder = 4
       end
       object cxReferences: TCheckBox
         Left = 318
-        Height = 24
+        Height = 17
         Top = 287
-        Width = 101
+        Width = 75
         Caption = 'References'
         TabOrder = 5
       end
       object bbApplyTable: TBitBtn
         Left = 6
         Height = 35
-        Top = 299
+        Top = 304
         Width = 75
         Anchors = [akLeft, akBottom]
         Caption = 'Apply'
@@ -109,50 +109,50 @@ object fmPermissionManage: TfmPermissionManage
       end
       object cbUsers: TComboBox
         Left = 18
-        Height = 29
+        Height = 21
         Top = 34
         Width = 236
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbTablesChange
         TabOrder = 7
       end
       object cxSelectGrant: TCheckBox
         Left = 345
-        Height = 24
+        Height = 17
         Top = 103
-        Width = 99
+        Width = 72
         Caption = 'With Grant'
         TabOrder = 8
       end
       object cxInsertGrant: TCheckBox
         Left = 345
-        Height = 24
+        Height = 17
         Top = 156
-        Width = 99
+        Width = 72
         Caption = 'With Grant'
         TabOrder = 9
       end
       object cxUpdateGrant: TCheckBox
         Left = 345
-        Height = 24
+        Height = 17
         Top = 203
-        Width = 99
+        Width = 72
         Caption = 'With Grant'
         TabOrder = 10
       end
       object cxDeleteGrant: TCheckBox
         Left = 342
-        Height = 24
+        Height = 17
         Top = 254
-        Width = 99
+        Width = 72
         Caption = 'With Grant'
         TabOrder = 11
       end
       object cxReferencesGrant: TCheckBox
         Left = 345
-        Height = 24
+        Height = 17
         Top = 309
-        Width = 99
+        Width = 72
         Caption = 'With Grant'
         TabOrder = 12
       end
@@ -193,10 +193,10 @@ object fmPermissionManage: TfmPermissionManage
       end
       object cbViewsUsers: TComboBox
         Left = 18
-        Height = 29
+        Height = 21
         Top = 34
         Width = 220
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbViewsUsersChange
         TabOrder = 0
       end
@@ -210,10 +210,10 @@ object fmPermissionManage: TfmPermissionManage
       end
       object cbViews: TComboBox
         Left = 18
-        Height = 31
+        Height = 21
         Top = 124
         Width = 220
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbViewsChange
         Style = csDropDownList
         TabOrder = 1
@@ -352,10 +352,10 @@ object fmPermissionManage: TfmPermissionManage
       end
       object cbProcUsers: TComboBox
         Left = 18
-        Height = 29
+        Height = 21
         Top = 34
         Width = 196
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbProcUsersChange
         TabOrder = 0
       end
@@ -377,7 +377,6 @@ object fmPermissionManage: TfmPermissionManage
         OnClick = clbProceduresClick
         OnKeyUp = clbProceduresKeyUp
         TabOrder = 1
-        TopIndex = -1
       end
       object bbApplyProc: TBitBtn
         Left = 6
@@ -415,10 +414,10 @@ object fmPermissionManage: TfmPermissionManage
       end
       object cbRolesUser: TComboBox
         Left = 18
-        Height = 29
+        Height = 21
         Top = 34
         Width = 188
-        ItemHeight = 0
+        ItemHeight = 13
         OnChange = cbRolesUserChange
         TabOrder = 0
       end
@@ -451,7 +450,6 @@ object fmPermissionManage: TfmPermissionManage
         OnClick = clbRolesClick
         OnKeyUp = clbRolesKeyUp
         TabOrder = 2
-        TopIndex = -1
       end
       object BitBtn1: TBitBtn
         Left = 102

+ 65 - 63
permissionmanage.lrs

@@ -1,41 +1,43 @@
+{ This is an automatically generated lazarus resource file }
+
 LazarusResources.Add('TfmPermissionManage','FORMDATA',[
   'TPF0'#19'TfmPermissionManage'#18'fmPermissionManage'#4'Left'#3#218#1#6'Heigh'
   +'t'#3'p'#1#3'Top'#3#204#0#5'Width'#3#6#2#7'Caption'#6#21'Permission Manageme'
   +'nt'#12'ClientHeight'#3'p'#1#11'ClientWidth'#3#6#2#7'OnClose'#7#9'FormClose'
-  +#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#7'1.0.4.0'#0#12'TPageCont'
+  +#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#7'1.2.0.3'#0#12'TPageCont'
   +'rol'#12'PageControl1'#4'Left'#2#0#6'Height'#3'p'#1#3'Top'#2#0#5'Width'#3#240
   +#1#10'ActivePage'#7#8'tsTables'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8
   +'akBottom'#0#8'TabIndex'#2#0#8'TabOrder'#2#0#0#9'TTabSheet'#8'tsTables'#7'Ca'
-  +'ption'#6#6'Tables'#12'ClientHeight'#3'Q'#1#11'ClientWidth'#3#236#1#0#6'TLab'
-  +'el'#6'Label1'#4'Left'#2#14#6'Height'#2#18#3'Top'#2#11#5'Width'#2'C'#7'Capti'
+  +'ption'#6#6'Tables'#12'ClientHeight'#3'V'#1#11'ClientWidth'#3#232#1#0#6'TLab'
+  +'el'#6'Label1'#4'Left'#2#14#6'Height'#2#13#3'Top'#2#11#5'Width'#2'/'#7'Capti'
   +'on'#6#9'User/Role'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#2#14#6
-  +'Height'#2#18#3'Top'#2'_'#5'Width'#2'%'#7'Caption'#6#5'Table'#11'ParentColor'
-  +#8#0#0#9'TComboBox'#8'cbTables'#4'Left'#2#18#6'Height'#2#31#3'Top'#2'|'#5'Wi'
-  +'dth'#3#236#0#10'ItemHeight'#2#0#8'OnChange'#7#14'cbTablesChange'#5'Style'#7
+  +'Height'#2#13#3'Top'#2'_'#5'Width'#2#26#7'Caption'#6#5'Table'#11'ParentColor'
+  +#8#0#0#9'TComboBox'#8'cbTables'#4'Left'#2#18#6'Height'#2#21#3'Top'#2'|'#5'Wi'
+  +'dth'#3#236#0#10'ItemHeight'#2#13#8'OnChange'#7#14'cbTablesChange'#5'Style'#7
   +#14'csDropDownList'#8'TabOrder'#2#0#0#0#6'TLabel'#6'Label3'#4'Left'#3'6'#1#6
-  +'Height'#2#18#3'Top'#2#10#5'Width'#2'S'#7'Caption'#6#11'Permissions'#11'Pare'
-  +'ntColor'#8#0#0#9'TCheckBox'#8'cxSelect'#4'Left'#3'='#1#6'Height'#2#24#3'Top'
-  +#2'V'#5'Width'#2'C'#7'Caption'#6#6'Select'#8'TabOrder'#2#1#0#0#9'TCheckBox'#8
-  +'cxInsert'#4'Left'#3'>'#1#6'Height'#2#24#3'Top'#3#138#0#5'Width'#2'A'#7'Capt'
+  +'Height'#2#13#3'Top'#2#10#5'Width'#2'7'#7'Caption'#6#11'Permissions'#11'Pare'
+  +'ntColor'#8#0#0#9'TCheckBox'#8'cxSelect'#4'Left'#3'='#1#6'Height'#2#17#3'Top'
+  +#2'V'#5'Width'#2'1'#7'Caption'#6#6'Select'#8'TabOrder'#2#1#0#0#9'TCheckBox'#8
+  +'cxInsert'#4'Left'#3'>'#1#6'Height'#2#17#3'Top'#3#138#0#5'Width'#2'1'#7'Capt'
   +'ion'#6#6'Insert'#8'TabOrder'#2#2#0#0#9'TCheckBox'#8'cxUpdate'#4'Left'#3'='#1
-  +#6'Height'#2#24#3'Top'#3#183#0#5'Width'#2'L'#7'Caption'#6#6'Update'#8'TabOrd'
-  +'er'#2#3#0#0#9'TCheckBox'#8'cxDelete'#4'Left'#3'='#1#6'Height'#2#24#3'Top'#3
-  +#236#0#5'Width'#2'F'#7'Caption'#6#6'Delete'#8'TabOrder'#2#4#0#0#9'TCheckBox'
-  +#12'cxReferences'#4'Left'#3'>'#1#6'Height'#2#24#3'Top'#3#31#1#5'Width'#2'e'#7
+  +#6'Height'#2#17#3'Top'#3#183#0#5'Width'#2'7'#7'Caption'#6#6'Update'#8'TabOrd'
+  +'er'#2#3#0#0#9'TCheckBox'#8'cxDelete'#4'Left'#3'='#1#6'Height'#2#17#3'Top'#3
+  +#236#0#5'Width'#2'3'#7'Caption'#6#6'Delete'#8'TabOrder'#2#4#0#0#9'TCheckBox'
+  +#12'cxReferences'#4'Left'#3'>'#1#6'Height'#2#17#3'Top'#3#31#1#5'Width'#2'K'#7
   +'Caption'#6#10'References'#8'TabOrder'#2#5#0#0#7'TBitBtn'#12'bbApplyTable'#4
-  +'Left'#2#6#6'Height'#2'#'#3'Top'#3'+'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'
+  +'Left'#2#6#6'Height'#2'#'#3'Top'#3'0'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'
   +#8'akBottom'#0#7'Caption'#6#5'Apply'#4'Kind'#7#4'bkOK'#7'OnClick'#7#17'bbApp'
   +'lyTableClick'#8'TabOrder'#2#6#0#0#9'TComboBox'#7'cbUsers'#4'Left'#2#18#6'He'
-  +'ight'#2#29#3'Top'#2'"'#5'Width'#3#236#0#10'ItemHeight'#2#0#8'OnChange'#7#14
+  +'ight'#2#21#3'Top'#2'"'#5'Width'#3#236#0#10'ItemHeight'#2#13#8'OnChange'#7#14
   +'cbTablesChange'#8'TabOrder'#2#7#0#0#9'TCheckBox'#13'cxSelectGrant'#4'Left'#3
-  +'Y'#1#6'Height'#2#24#3'Top'#2'g'#5'Width'#2'c'#7'Caption'#6#10'With Grant'#8
+  +'Y'#1#6'Height'#2#17#3'Top'#2'g'#5'Width'#2'H'#7'Caption'#6#10'With Grant'#8
   +'TabOrder'#2#8#0#0#9'TCheckBox'#13'cxInsertGrant'#4'Left'#3'Y'#1#6'Height'#2
-  +#24#3'Top'#3#156#0#5'Width'#2'c'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#9
-  +#0#0#9'TCheckBox'#13'cxUpdateGrant'#4'Left'#3'Y'#1#6'Height'#2#24#3'Top'#3
-  +#203#0#5'Width'#2'c'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#10#0#0#9'TChe'
-  +'ckBox'#13'cxDeleteGrant'#4'Left'#3'V'#1#6'Height'#2#24#3'Top'#3#254#0#5'Wid'
-  +'th'#2'c'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#11#0#0#9'TCheckBox'#17'c'
-  +'xReferencesGrant'#4'Left'#3'Y'#1#6'Height'#2#24#3'Top'#3'5'#1#5'Width'#2'c'
+  +#17#3'Top'#3#156#0#5'Width'#2'H'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#9
+  +#0#0#9'TCheckBox'#13'cxUpdateGrant'#4'Left'#3'Y'#1#6'Height'#2#17#3'Top'#3
+  +#203#0#5'Width'#2'H'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#10#0#0#9'TChe'
+  +'ckBox'#13'cxDeleteGrant'#4'Left'#3'V'#1#6'Height'#2#17#3'Top'#3#254#0#5'Wid'
+  +'th'#2'H'#7'Caption'#6#10'With Grant'#8'TabOrder'#2#11#0#0#9'TCheckBox'#17'c'
+  +'xReferencesGrant'#4'Left'#3'Y'#1#6'Height'#2#17#3'Top'#3'5'#1#5'Width'#2'H'
   +#7'Caption'#6#10'With Grant'#8'TabOrder'#2#12#0#0#9'TCheckBox'#5'cxAll'#4'Le'
   +'ft'#3'>'#1#6'Height'#2#24#3'Top'#2'"'#5'Width'#2'B'#8'AutoSize'#8#7'Caption'
   +#6#3'All'#10'Font.Style'#11#6'fsBold'#0#10'ParentFont'#8#8'TabOrder'#2#13#0#0
@@ -45,12 +47,12 @@ LazarusResources.Add('TfmPermissionManage','FORMDATA',[
   +'tion'#6#5'Views'#12'ClientHeight'#3'Q'#1#11'ClientWidth'#3#236#1#0#6'TLabel'
   +#6'Label8'#4'Left'#2#14#6'Height'#2#18#3'Top'#2#11#5'Width'#2'C'#7'Caption'#6
   +#9'User/Role'#11'ParentColor'#8#0#0#9'TComboBox'#12'cbViewsUsers'#4'Left'#2
-  +#18#6'Height'#2#29#3'Top'#2'"'#5'Width'#3#220#0#10'ItemHeight'#2#0#8'OnChang'
-  +'e'#7#18'cbViewsUsersChange'#8'TabOrder'#2#0#0#0#6'TLabel'#6'Label9'#4'Left'
+  +#18#6'Height'#2#21#3'Top'#2'"'#5'Width'#3#220#0#10'ItemHeight'#2#13#8'OnChan'
+  +'ge'#7#18'cbViewsUsersChange'#8'TabOrder'#2#0#0#0#6'TLabel'#6'Label9'#4'Left'
   +#2#14#6'Height'#2#18#3'Top'#2'_'#5'Width'#2'"'#7'Caption'#6#4'View'#11'Paren'
-  +'tColor'#8#0#0#9'TComboBox'#7'cbViews'#4'Left'#2#18#6'Height'#2#31#3'Top'#2
-  +'|'#5'Width'#3#220#0#10'ItemHeight'#2#0#8'OnChange'#7#13'cbViewsChange'#5'St'
-  +'yle'#7#14'csDropDownList'#8'TabOrder'#2#1#0#0#7'TBitBtn'#11'bbApplyView'#4
+  +'tColor'#8#0#0#9'TComboBox'#7'cbViews'#4'Left'#2#18#6'Height'#2#21#3'Top'#2
+  +'|'#5'Width'#3#220#0#10'ItemHeight'#2#13#8'OnChange'#7#13'cbViewsChange'#5'S'
+  +'tyle'#7#14'csDropDownList'#8'TabOrder'#2#1#0#0#7'TBitBtn'#11'bbApplyView'#4
   +'Left'#2#6#6'Height'#2'!'#3'Top'#3'+'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'
   +#8'akBottom'#0#7'Caption'#6#5'Apply'#4'Kind'#7#4'bkOK'#7'OnClick'#7#16'bbApp'
   +'lyViewClick'#8'TabOrder'#2#2#0#0#6'TLabel'#7'Label10'#4'Left'#3'6'#1#6'Heig'
@@ -81,39 +83,39 @@ LazarusResources.Add('TfmPermissionManage','FORMDATA',[
   +#0#0#0#9'TTabSheet'#12'tsProcedures'#7'Caption'#6#10'Procedures'#12'ClientHe'
   +'ight'#3'Q'#1#11'ClientWidth'#3#236#1#0#6'TLabel'#6'Label4'#4'Left'#2#12#6'H'
   +'eight'#2#18#3'Top'#2#10#5'Width'#2'C'#7'Caption'#6#9'User/Role'#11'ParentCo'
-  +'lor'#8#0#0#9'TComboBox'#11'cbProcUsers'#4'Left'#2#18#6'Height'#2#29#3'Top'#2
-  +'"'#5'Width'#3#196#0#10'ItemHeight'#2#0#8'OnChange'#7#17'cbProcUsersChange'#8
-  +'TabOrder'#2#0#0#0#6'TLabel'#6'Label5'#4'Left'#3#230#0#6'Height'#2#18#3'Top'
-  +#2#11#5'Width'#2'S'#7'Caption'#6#11'Permissions'#11'ParentColor'#8#0#0#13'TC'
-  +'heckListBox'#13'clbProcedures'#4'Left'#3#246#0#6'Height'#3#1#1#3'Top'#2''''
-  +#5'Width'#3#211#0#7'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#10'ItemHeig'
-  +'ht'#2#0#7'OnClick'#7#18'clbProceduresClick'#7'OnKeyUp'#7#18'clbProceduresKe'
-  +'yUp'#8'TabOrder'#2#1#8'TopIndex'#2#255#0#0#7'TBitBtn'#11'bbApplyProc'#4'Lef'
-  +'t'#2#6#6'Height'#2'!'#3'Top'#3'('#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8
-  +'akBottom'#0#7'Caption'#6#5'Apply'#4'Kind'#7#4'bkOK'#7'OnClick'#7#16'bbApply'
-  +'ProcClick'#8'TabOrder'#2#2#0#0#9'TCheckBox'#11'cxProcGrant'#4'Left'#3#246#0
-  +#6'Height'#2#24#3'Top'#3'+'#1#5'Width'#2'c'#7'Anchors'#11#6'akLeft'#8'akBott'
-  +'om'#0#7'Caption'#6#10'With Grant'#8'OnChange'#7#17'cxProcGrantChange'#8'Tab'
-  +'Order'#2#3#0#0#0#9'TTabSheet'#7'tsRoles'#7'Caption'#6#5'Roles'#12'ClientHei'
-  +'ght'#3'Q'#1#11'ClientWidth'#3#236#1#0#6'TLabel'#6'Label6'#4'Left'#2#12#6'He'
-  +'ight'#2#18#3'Top'#2#10#5'Width'#2' '#7'Caption'#6#4'User'#11'ParentColor'#8
-  +#0#0#9'TComboBox'#11'cbRolesUser'#4'Left'#2#18#6'Height'#2#29#3'Top'#2'"'#5
-  +'Width'#3#188#0#10'ItemHeight'#2#0#8'OnChange'#7#17'cbRolesUserChange'#8'Tab'
-  +'Order'#2#0#0#0#6'TLabel'#6'Label7'#4'Left'#3#230#0#6'Height'#2#18#3'Top'#2
-  +#11#5'Width'#2'S'#7'Caption'#6#11'Permissions'#11'ParentColor'#8#0#0#7'TBitB'
-  +'tn'#12'bbApplyRoles'#4'Left'#2#12#6'Height'#2'#'#3'Top'#3'*'#1#5'Width'#2'K'
-  +#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#5'Apply'#4'Kind'#7#4'bkO'
-  +'K'#7'OnClick'#7#17'bbApplyRolesClick'#8'TabOrder'#2#1#0#0#13'TCheckListBox'
-  +#8'clbRoles'#4'Left'#3#246#0#6'Height'#3#1#1#3'Top'#2''''#5'Width'#3#211#0#7
-  +'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#10'ItemHeight'#2#0#7'OnClick'#7
-  +#13'clbRolesClick'#7'OnKeyUp'#7#13'clbRolesKeyUp'#8'TabOrder'#2#2#8'TopIndex'
-  +#2#255#0#0#7'TBitBtn'#7'BitBtn1'#4'Left'#2'f'#6'Height'#2'#'#3'Top'#3'*'#1#5
-  +'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#7'Refresh'#7
-  +'OnClick'#7#12'BitBtn1Click'#8'TabOrder'#2#3#0#0#9'TCheckBox'#11'cxRoleGrant'
-  +#4'Left'#3#246#0#6'Height'#2#24#3'Top'#3'0'#1#5'Width'#2'i'#7'Anchors'#11#6
-  +'akLeft'#8'akBottom'#0#7'Caption'#6#10'With Admin'#8'OnChange'#7#17'cxRoleGr'
-  +'antChange'#8'TabOrder'#2#4#0#0#0#0#7'TBitBtn'#7'bbClose'#4'Left'#3#232#1#6
-  +'Height'#2#24#3'Top'#2#255#5'Width'#2#27#7'Anchors'#11#5'akTop'#7'akRight'#0
-  +#7'Caption'#6#4' X  '#5'Color'#4#219#242#247#0#10'Font.Style'#11#6'fsBold'#0
-  +#7'OnClick'#7#12'bbCloseClick'#10'ParentFont'#8#8'TabOrder'#2#1#0#0#0
+  +'lor'#8#0#0#9'TComboBox'#11'cbProcUsers'#4'Left'#2#18#6'Height'#2#21#3'Top'#2
+  +'"'#5'Width'#3#196#0#10'ItemHeight'#2#13#8'OnChange'#7#17'cbProcUsersChange'
+  +#8'TabOrder'#2#0#0#0#6'TLabel'#6'Label5'#4'Left'#3#230#0#6'Height'#2#18#3'To'
+  +'p'#2#11#5'Width'#2'S'#7'Caption'#6#11'Permissions'#11'ParentColor'#8#0#0#13
+  +'TCheckListBox'#13'clbProcedures'#4'Left'#3#246#0#6'Height'#3#1#1#3'Top'#2
+  +''''#5'Width'#3#211#0#7'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#10'Item'
+  +'Height'#2#0#7'OnClick'#7#18'clbProceduresClick'#7'OnKeyUp'#7#18'clbProcedur'
+  +'esKeyUp'#8'TabOrder'#2#1#0#0#7'TBitBtn'#11'bbApplyProc'#4'Left'#2#6#6'Heigh'
+  +'t'#2'!'#3'Top'#3'('#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7
+  +'Caption'#6#5'Apply'#4'Kind'#7#4'bkOK'#7'OnClick'#7#16'bbApplyProcClick'#8'T'
+  +'abOrder'#2#2#0#0#9'TCheckBox'#11'cxProcGrant'#4'Left'#3#246#0#6'Height'#2#24
+  +#3'Top'#3'+'#1#5'Width'#2'c'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'
+  +#6#10'With Grant'#8'OnChange'#7#17'cxProcGrantChange'#8'TabOrder'#2#3#0#0#0#9
+  +'TTabSheet'#7'tsRoles'#7'Caption'#6#5'Roles'#12'ClientHeight'#3'Q'#1#11'Clie'
+  +'ntWidth'#3#236#1#0#6'TLabel'#6'Label6'#4'Left'#2#12#6'Height'#2#18#3'Top'#2
+  +#10#5'Width'#2' '#7'Caption'#6#4'User'#11'ParentColor'#8#0#0#9'TComboBox'#11
+  +'cbRolesUser'#4'Left'#2#18#6'Height'#2#21#3'Top'#2'"'#5'Width'#3#188#0#10'It'
+  +'emHeight'#2#13#8'OnChange'#7#17'cbRolesUserChange'#8'TabOrder'#2#0#0#0#6'TL'
+  +'abel'#6'Label7'#4'Left'#3#230#0#6'Height'#2#18#3'Top'#2#11#5'Width'#2'S'#7
+  +'Caption'#6#11'Permissions'#11'ParentColor'#8#0#0#7'TBitBtn'#12'bbApplyRoles'
+  +#4'Left'#2#12#6'Height'#2'#'#3'Top'#3'*'#1#5'Width'#2'K'#7'Anchors'#11#6'akL'
+  +'eft'#8'akBottom'#0#7'Caption'#6#5'Apply'#4'Kind'#7#4'bkOK'#7'OnClick'#7#17
+  +'bbApplyRolesClick'#8'TabOrder'#2#1#0#0#13'TCheckListBox'#8'clbRoles'#4'Left'
+  +#3#246#0#6'Height'#3#1#1#3'Top'#2''''#5'Width'#3#211#0#7'Anchors'#11#5'akTop'
+  +#6'akLeft'#8'akBottom'#0#10'ItemHeight'#2#0#7'OnClick'#7#13'clbRolesClick'#7
+  +'OnKeyUp'#7#13'clbRolesKeyUp'#8'TabOrder'#2#2#0#0#7'TBitBtn'#7'BitBtn1'#4'Le'
+  +'ft'#2'f'#6'Height'#2'#'#3'Top'#3'*'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'
+  +#8'akBottom'#0#7'Caption'#6#7'Refresh'#7'OnClick'#7#12'BitBtn1Click'#8'TabOr'
+  +'der'#2#3#0#0#9'TCheckBox'#11'cxRoleGrant'#4'Left'#3#246#0#6'Height'#2#24#3
+  +'Top'#3'0'#1#5'Width'#2'i'#7'Anchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6
+  +#10'With Admin'#8'OnChange'#7#17'cxRoleGrantChange'#8'TabOrder'#2#4#0#0#0#0#7
+  +'TBitBtn'#7'bbClose'#4'Left'#3#232#1#6'Height'#2#24#3'Top'#2#255#5'Width'#2
+  +#27#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#4' X  '#5'Color'#4#219
+  +#242#247#0#10'Font.Style'#11#6'fsBold'#0#7'OnClick'#7#12'bbCloseClick'#10'Pa'
+  +'rentFont'#8#8'TabOrder'#2#1#0#0#0
 ]);

+ 77 - 68
permissionmanage.pas

@@ -318,20 +318,22 @@ begin
   if (cbUsers.Text <> '') and (cbTables.ItemIndex <> -1) then
   begin
     List:= TStringList.Create;
+    try
+      if cxAll.Checked then
+        ComposeTablePermissionSQL(cbTables.Text, 'All', cxAll.Checked, cxAllGrant.Checked, List)
+      else
+      begin
+        ComposeTablePermissionSQL(cbTables.Text, 'Select', cxSelect.Checked, cxSelectGrant.Checked, List);
+        ComposeTablePermissionSQL(cbTables.Text, 'Insert', cxInsert.Checked, cxInsertGrant.Checked, List);
+        ComposeTablePermissionSQL(cbTables.Text, 'Update', cxUpdate.Checked, cxUpdateGrant.Checked, List);
+        ComposeTablePermissionSQL(cbTables.Text, 'Delete', cxDelete.Checked, cxDeleteGrant.Checked, List);
+        ComposeTablePermissionSQL(cbTables.Text, 'References', cxReferences.Checked, cxReferencesGrant.Checked, List);
+      end;
 
-    if cxAll.Checked then
-      ComposeTablePermissionSQL(cbTables.Text, 'All', cxAll.Checked, cxAllGrant.Checked, List)
-    else
-    begin
-      ComposeTablePermissionSQL(cbTables.Text, 'Select', cxSelect.Checked, cxSelectGrant.Checked, List);
-      ComposeTablePermissionSQL(cbTables.Text, 'Insert', cxInsert.Checked, cxInsertGrant.Checked, List);
-      ComposeTablePermissionSQL(cbTables.Text, 'Update', cxUpdate.Checked, cxUpdateGrant.Checked, List);
-      ComposeTablePermissionSQL(cbTables.Text, 'Delete', cxDelete.Checked, cxDeleteGrant.Checked, List);
-      ComposeTablePermissionSQL(cbTables.Text, 'References', cxReferences.Checked, cxReferencesGrant.Checked, List);
+      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbTables.Text, List.Text, fOnCommitProcedure);
+    finally
+      List.Free;
     end;
-
-    fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbTables.Text, List.Text, fOnCommitProcedure);
-    List.Free;
     Close;
     Parent.Free;
   end
@@ -346,20 +348,22 @@ begin
   if (cbViewsUsers.Text <> '') and (cbViews.ItemIndex <> -1) then
   begin
     List:= TStringList.Create;
+    try
+      if cxViewAll.Checked then
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'All', cxViewAll.Checked, cxViewAllGrant.Checked, List)
+      else
+      begin
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Select', cxViewSelect.Checked, cxViewSelectGrant.Checked, List);
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Insert', cxViewInsert.Checked, cxViewInsertGrant.Checked, List);
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Update', cxViewUpdate.Checked, cxViewUpdateGrant.Checked, List);
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Delete', cxViewDelete.Checked, cxViewDeleteGrant.Checked, List);
+        ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'References', cxViewReferences.Checked, cxViewReferencesGrant.Checked, List);
+      end;
 
-    if cxViewAll.Checked then
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'All', cxViewAll.Checked, cxViewAllGrant.Checked, List)
-    else
-    begin
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Select', cxViewSelect.Checked, cxViewSelectGrant.Checked, List);
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Insert', cxViewInsert.Checked, cxViewInsertGrant.Checked, List);
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Update', cxViewUpdate.Checked, cxViewUpdateGrant.Checked, List);
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'Delete', cxViewDelete.Checked, cxViewDeleteGrant.Checked, List);
-      ComposeTablePermissionSQL('"' + cbViews.Text + '"', 'References', cxViewReferences.Checked, cxViewReferencesGrant.Checked, List);
+      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbViews.Text, List.Text, fOnCommitProcedure);
+    finally
+      List.Free;
     end;
-
-    fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbViews.Text, List.Text, fOnCommitProcedure);
-    List.Free;
     Close;
     Parent.Free;
   end
@@ -388,30 +392,33 @@ begin
   if Trim(cbProcUsers.Text) <> '' then
   begin
     List:= TStringList.Create;
-    For i:= 0 to clbProcedures.Items.Count - 1 do
-    begin
-      if clbProcedures.Checked[i] and
-        ((ProcList.IndexOf(clbProcedures.Items[i]) = -1) or (ProcGrant[i] and (not OrigProcGrant[i]))) then // Grant this proc
-        begin
-          Line:= 'grant execute on procedure ' + clbProcedures.Items[i] + ' to ' + cbProcUsers.Text;
-          if ProcGrant[i] then
-            Line:= Line + ' with grant option';
-          List.Add(Line + ';');
-
-        end;
-
-      if (not clbProcedures.Checked[i]) and (ProcList.IndexOf(clbProcedures.Items[i]) <> -1) then // Remove this proc
-        List.Add('Revoke execute on procedure ' + clbProcedures.Items[i] + ' from ' + cbProcUsers.Text + ';');
-    end;
-    if List.Count > 0 then
-    begin
-      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbProcUsers.Text, List.Text, fOnCommitProcedure);
+    try
+      For i:= 0 to clbProcedures.Items.Count - 1 do
+      begin
+        if clbProcedures.Checked[i] and
+          ((ProcList.IndexOf(clbProcedures.Items[i]) = -1) or (ProcGrant[i] and (not OrigProcGrant[i]))) then // Grant this proc
+          begin
+            Line:= 'grant execute on procedure ' + clbProcedures.Items[i] + ' to ' + cbProcUsers.Text;
+            if ProcGrant[i] then
+              Line:= Line + ' with grant option';
+            List.Add(Line + ';');
+
+          end;
+
+        if (not clbProcedures.Checked[i]) and (ProcList.IndexOf(clbProcedures.Items[i]) <> -1) then // Remove this proc
+          List.Add('Revoke execute on procedure ' + clbProcedures.Items[i] + ' from ' + cbProcUsers.Text + ';');
+      end;
+      if List.Count > 0 then
+      begin
+        fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbProcUsers.Text, List.Text, fOnCommitProcedure);
+        Close;
+        Parent.Free;
+      end
+      else
+        ShowMessage('There is no change');
+    finally
       List.Free;
-      Close;
-      Parent.Free;
-    end
-    else
-      ShowMessage('There is no change');
+    end;
   end;
 end;
 
@@ -424,32 +431,34 @@ begin
   if Trim(cbRolesUser.Text) <> '' then
   begin
     List:= TStringList.Create;
-    For i:= 0 to clbRoles.Items.Count - 1 do
-    begin
-      if clbRoles.Checked[i] and
-        ((RoleList.IndexOf(clbRoles.Items[i]) = -1) or (RoleGrant[i] and (not OrigRoleGrant[i]))) then // Grant this Role
+    try
+      For i:= 0 to clbRoles.Items.Count - 1 do
       begin
-        Line:= 'grant ' + clbRoles.Items[i] + ' to ' + cbRolesUser.Text;
-        if RoleGrant[i] then
-          Line:= Line + ' with admin option';
-        List.Add(Line + ';');
-      end;
+        if clbRoles.Checked[i] and
+          ((RoleList.IndexOf(clbRoles.Items[i]) = -1) or (RoleGrant[i] and (not OrigRoleGrant[i]))) then // Grant this Role
+        begin
+          Line:= 'grant ' + clbRoles.Items[i] + ' to ' + cbRolesUser.Text;
+          if RoleGrant[i] then
+            Line:= Line + ' with admin option';
+          List.Add(Line + ';');
+        end;
 
-      if (not clbRoles.Checked[i]) and (RoleList.IndexOf(clbRoles.Items[i]) <> -1) then // Remove this Role
-        List.Add('Revoke ' + clbRoles.Items[i] + ' from ' + cbRolesUser.Text + ';');
-    end;
+        if (not clbRoles.Checked[i]) and (RoleList.IndexOf(clbRoles.Items[i]) <> -1) then // Remove this Role
+          List.Add('Revoke ' + clbRoles.Items[i] + ' from ' + cbRolesUser.Text + ';');
+      end;
 
-    if List.Count > 0 then
-    begin
-      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbRolesUser.Text, List.Text, fOnCommitProcedure);
+      if List.Count > 0 then
+      begin
+        fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Permission for: ' + cbRolesUser.Text, List.Text, fOnCommitProcedure);
+        Close;
+        Parent.Free;
+      end
+      else
+        ShowMessage('There is no change');
+    finally
       List.Free;
-      Close;
-      Parent.Free;
-    end
-    else
-      ShowMessage('There is no change');
+    end;
   end;
-
 end;
 
 procedure TfmPermissionManage.cbProcUsersChange(Sender: TObject);

+ 77 - 76
querywindow.pas

@@ -396,91 +396,92 @@ begin
     PKName:= fmMain.GetPrimaryKeyIndexName(fdbIndex, ATableName, ConstraintName);
     if PKName <> '' then
     begin
-
-      aQuery:= TSQLQuery.Create(nil);
-      aQuery.DataBase:= ibConnection;
-      aQuery.Transaction:= SqlTrans;
       KeyList:= TStringList.Create;
       Fieldslist:= tstringList.Create;
-
-      // Get primary key fields
-      fmMain.GetIndexFields(ATableName, PKName, aQuery, KeyList);
-      fmMain.GetFields(fdbIndex, ATableName, FieldsList);
-      WhereClause:= 'where ';
-
-      RecordSet.DisableControls;
-      // Check modified fields
-      for i:= 0 to High(ModifiedRecords[TabIndex]) do
-      begin
-        FieldsSQL:= '';
-        RecordSet.RecNo:= ModifiedRecords[TabIndex][i];
-        for x:= 0 to RecordSet.Fields.Count - 1 do
-        if FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1 then // Field exist in origional table
-
-        if (RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
-        begin
-         if FieldsSQL <> '' then
-             FieldsSQL += ',';
-           FieldsSQL += RecordSet.Fields[x].FieldName + '=';
-
-           // Typecast field values according to thier main type
-           case RecordSet.Fields[x].DataType of
-            ftInteger, ftSmallint: FieldsSQL += IntToStr(RecordSet.Fields[x].NewValue);
-            ftFloat: FieldsSQL += FloatToStr(RecordSet.Fields[x].NewValue);
-            ftTimeStamp, ftDateTime: FieldsSQL += '''' + DateTimeToStr(RecordSet.Fields[x].NewValue) + '''';
-            ftTime: FieldsSQL += '''' + TimeToStr(RecordSet.Fields[x].NewValue) + '''';
-            ftDate: FieldsSQL += '''' + DateToStr(RecordSet.Fields[x].NewValue) + '''';
-
-           else // Other types like string
-              FieldsSQL += '''' + RecordSet.Fields[x].NewValue + '''';
-
-         end;
-        end;
-
-
-        // Update current record
-        if FieldsSQL <> '' then
+      aQuery:= TSQLQuery.Create(nil);
+      try
+        aQuery.DataBase:= ibConnection;
+        aQuery.Transaction:= SqlTrans;
+
+        // Get primary key fields
+        fmMain.GetIndexFields(ATableName, PKName, aQuery, KeyList);
+        fmMain.GetFields(fdbIndex, ATableName, FieldsList);
+        WhereClause:= 'where ';
+
+        RecordSet.DisableControls;
+        // Check modified fields
+        for i:= Low(ModifiedRecords[TabIndex]) to High(ModifiedRecords[TabIndex]) do
         begin
-          aQuery.Close;
-          aQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
+         FieldsSQL:= '';
+         RecordSet.RecNo:= ModifiedRecords[TabIndex][i];
+         for x:= 0 to RecordSet.Fields.Count - 1 do
+         if FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1 then // Field exist in origional table
+
+         if (RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
+         begin
+          if FieldsSQL <> '' then
+              FieldsSQL += ',';
+            FieldsSQL += RecordSet.Fields[x].FieldName + '=';
+
+            // Typecast field values according to thier main type
+            case RecordSet.Fields[x].DataType of
+             ftInteger, ftSmallint: FieldsSQL += IntToStr(RecordSet.Fields[x].NewValue);
+             ftFloat: FieldsSQL += FloatToStr(RecordSet.Fields[x].NewValue);
+             ftTimeStamp, ftDateTime: FieldsSQL += '''' + DateTimeToStr(RecordSet.Fields[x].NewValue) + '''';
+             ftTime: FieldsSQL += '''' + TimeToStr(RecordSet.Fields[x].NewValue) + '''';
+             ftDate: FieldsSQL += '''' + DateToStr(RecordSet.Fields[x].NewValue) + '''';
 
-          WhereClause:= 'where ';
-          // where clause
-          for x:= 0 to KeyList.Count - 1 do
-          if Trim(KeyList[x]) <> '' then
-          begin
-            WhereClause += KeyList[x] + ' = ';
+            else // Other types like string
+               FieldsSQL += '''' + RecordSet.Fields[x].NewValue + '''';
 
-            // Typecase index values
-            case RecordSet.Fields[x].DataType of
-             ftInteger, ftSmallint: WhereClause += IntToStr(RecordSet.Fields[x].OldValue);
-             ftFloat: WhereClause += FloatToStr(RecordSet.Fields[x].OldValue);
-            else
-               WhereClause += '''' + RecordSet.Fields[x].OldValue + '''';
-            end;
-            if x < KeyList.Count - 1 then
-              WhereClause += ' and ';
           end;
+         end;
 
-          aQuery.SQL.Add(WhereClause);
-          aQuery.ExecSQL;
-          (Sender as TBitBtn).Visible:= False;
 
-          // Auto commit
-          if cxAutoCommit.Checked then
-            SqlTrans.CommitRetaining
-          else
-            EnableCommitButton;
+         // Update current record
+         if FieldsSQL <> '' then
+         begin
+           aQuery.Close;
+           aQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
+
+           WhereClause:= 'where ';
+           // where clause
+           for x:= 0 to KeyList.Count - 1 do
+           if Trim(KeyList[x]) <> '' then
+           begin
+             WhereClause += KeyList[x] + ' = ';
+
+             // Typecase index values
+             case RecordSet.Fields[x].DataType of
+              ftInteger, ftSmallint: WhereClause += IntToStr(RecordSet.Fields[x].OldValue);
+              ftFloat: WhereClause += FloatToStr(RecordSet.Fields[x].OldValue);
+             else
+                WhereClause += '''' + RecordSet.Fields[x].OldValue + '''';
+             end;
+             if x < KeyList.Count - 1 then
+               WhereClause += ' and ';
+           end;
+
+           aQuery.SQL.Add(WhereClause);
+           aQuery.ExecSQL;
+           (Sender as TBitBtn).Visible:= False;
+
+           // Auto commit
+           if cxAutoCommit.Checked then
+             SqlTrans.CommitRetaining
+           else
+             EnableCommitButton;
+         end;
         end;
-      end;
-
-      // Reset ModifedRecords pointer
-      ModifiedRecords[TabIndex]:= nil;
 
-      RecordSet.EnableControls;
-      FieldsList.Free;
-      KeyList.Free;
-      aQuery.Free;
+        // Reset ModifedRecords pointer
+        ModifiedRecords[TabIndex]:= nil;
+        RecordSet.EnableControls;
+      finally
+        FieldsList.Free;
+        KeyList.Free;
+        aQuery.Free;
+      end;
     end
     else
       ShowMessage('There is no primary key on the table: ' + aTableName);
@@ -1487,7 +1488,7 @@ var
   i: Integer;
   CannotFree: Boolean;
 begin
-  for i:= High(ResultControls) downto  0 do
+  for i:= High(ResultControls) downto Low(ResultControls) do
   begin
     if ResultControls[i] is TSQLQuery then
     begin

+ 263 - 238
scriptdb.pas

@@ -153,90 +153,92 @@ begin
   ScriptList.Clear;
   ScriptList.Add('create table ' + ATableName + ' (');
   CalculatedList:= TStringList.Create;
-
-  // Fields
-  with fmMain.SQLQuery1 do
-  while not EOF do
-  begin
-    Skipped:= False;
-    if (FieldByName('Computed_Source').AsString = '') and
-     ((Pos('CHAR', Trim(FieldByName('Field_Type_Str').AsString)) = 0) or
-     (Trim(FieldByName('Field_Collation').AsString) = 'NONE') or
-     (FieldByName('Field_Collation').IsNull)) then
+  try
+    // Fields
+    with fmMain.SQLQuery1 do
+    while not EOF do
     begin
-      // Field Name
-      FieldLine:= Trim(FieldByName('Field_Name').AsString) + ' ';
-
-      // Field Type
-      if FieldByName('Field_Type_Int').AsInteger in [7, 8, 16] then
-        FieldLine:= FieldLine + fmMain.GetNumericFieldType(FieldByName('Field_Type_Int').AsInteger,
-          FieldByName('Field_SubType').AsInteger, FieldByName('Field_Length').AsInteger,
-          FieldByName('Field_Scale').AsInteger)
-      else
-        FieldLine:= FieldLine + Trim(FieldByName('Field_Type_Str').AsString);
-
-      if Pos('char', LowerCase(FieldByName('Field_Type_Str').AsString)) > 0 then
-        FieldLine:= FieldLine + '(' + FieldByName('Character_Leng').AsString + ') ';
-
-      // Default value
-      DefaultValue:= Trim(FieldByName('Field_Default_Value').AsString);
-      if DefaultValue <> '' then
+      Skipped:= False;
+      if (FieldByName('Computed_Source').AsString = '') and
+       ((Pos('CHAR', Trim(FieldByName('Field_Type_Str').AsString)) = 0) or
+       (Trim(FieldByName('Field_Collation').AsString) = 'NONE') or
+       (FieldByName('Field_Collation').IsNull)) then
       begin
-        if pos('default', DefaultValue) <> 1 then
-          DefaultValue:= ' default ''' + DefaultValue + '''';
+        // Field Name
+        FieldLine:= Trim(FieldByName('Field_Name').AsString) + ' ';
+
+        // Field Type
+        if FieldByName('Field_Type_Int').AsInteger in [7, 8, 16] then
+          FieldLine:= FieldLine + fmMain.GetNumericFieldType(FieldByName('Field_Type_Int').AsInteger,
+            FieldByName('Field_SubType').AsInteger, FieldByName('Field_Length').AsInteger,
+            FieldByName('Field_Scale').AsInteger)
+        else
+          FieldLine:= FieldLine + Trim(FieldByName('Field_Type_Str').AsString);
+
+        if Pos('char', LowerCase(FieldByName('Field_Type_Str').AsString)) > 0 then
+          FieldLine:= FieldLine + '(' + FieldByName('Character_Leng').AsString + ') ';
+
+        // Default value
+        DefaultValue:= Trim(FieldByName('Field_Default_Value').AsString);
+        if DefaultValue <> '' then
+        begin
+          if pos('default', DefaultValue) <> 1 then
+            DefaultValue:= ' default ''' + DefaultValue + '''';
+
+          FieldLine:= FieldLine + ' ' + DefaultValue;
+        end;
+
+        // Null/Not null
+        if FieldByName('field_not_null_constraint').AsString = '1' then
+           FieldLine:= FieldLine + ' not null ';
 
-        FieldLine:= FieldLine + ' ' + DefaultValue;
-      end;
-
-      // Null/Not null
-      if FieldByName('field_not_null_constraint').AsString = '1' then
-         FieldLine:= FieldLine + ' not null ';
-
-    end
-    else
-      Skipped:= True;
+      end
+      else
+        Skipped:= True;
 
-    // Computed Fields
-    if FieldByName('Computed_Source').AsString <> '' then
-      CalculatedList.Add('ALTER TABLE ' + ATableName + ' ADD ' +
-        Trim(FieldByName('Field_Name').AsString) + ' COMPUTED BY ' + FieldByName('Computed_Source').AsString + ';');
+      // Computed Fields
+      if FieldByName('Computed_Source').AsString <> '' then
+        CalculatedList.Add('ALTER TABLE ' + ATableName + ' ADD ' +
+          Trim(FieldByName('Field_Name').AsString) + ' COMPUTED BY ' + FieldByName('Computed_Source').AsString + ';');
 
-    Next;
+      Next;
 
-    if not Skipped then
-    begin
-      if not EOF then
-        FieldLine:= FieldLine + ',';
-      ScriptList.Add(FieldLine);
+      if not Skipped then
+      begin
+        if not EOF then
+          FieldLine:= FieldLine + ',';
+        ScriptList.Add(FieldLine);
+      end;
     end;
-  end;
 
-  if Pos(',', ScriptList[ScriptList.Count - 1]) > 0 then
-    ScriptList[ScriptList.Count - 1]:= Copy(ScriptList[ScriptList.Count - 1], 1,
-      Length(ScriptList[ScriptList.Count - 1]) - 1);
+    if Pos(',', ScriptList[ScriptList.Count - 1]) > 0 then
+      ScriptList[ScriptList.Count - 1]:= Copy(ScriptList[ScriptList.Count - 1], 1,
+        Length(ScriptList[ScriptList.Count - 1]) - 1);
 
-  fmMain.SQLQuery1.Close;
+    fmMain.SQLQuery1.Close;
 
-  // Primary Keys
-  PKFieldsList:= TStringList.Create;
-  PKeyName:= fmMain.GetPrimaryKeyIndexName(dbIndex, ATableName, ConstraintName);
-  if PKeyName <> '' then
-  begin
-    fmMain.GetConstraintFields(ATableName, PKeyName, PKFieldsList);
-    FieldLine:= 'constraint ' + PKeyName + ' primary key (';
-    for i:= 0 to PKFieldsList.Count - 1 do
-      FieldLine:= FieldLine + PKFieldsList[i] + ', ';
-    if PKFieldsList.Count > 0 then
+    // Primary Keys
+    PKFieldsList:= TStringList.Create;
+    PKeyName:= fmMain.GetPrimaryKeyIndexName(dbIndex, ATableName, ConstraintName);
+    if PKeyName <> '' then
     begin
-      Delete(FieldLine, Length(FieldLine) - 1, 2);
-      FieldLine:= FieldLine + ')';
-      ScriptList.Add(', ' + FieldLine);
+      fmMain.GetConstraintFields(ATableName, PKeyName, PKFieldsList);
+      FieldLine:= 'constraint ' + PKeyName + ' primary key (';
+      for i:= 0 to PKFieldsList.Count - 1 do
+        FieldLine:= FieldLine + PKFieldsList[i] + ', ';
+      if PKFieldsList.Count > 0 then
+      begin
+        Delete(FieldLine, Length(FieldLine) - 1, 2);
+        FieldLine:= FieldLine + ')';
+        ScriptList.Add(', ' + FieldLine);
+      end;
     end;
-  end;
 
-  ScriptList.Add(');');
-  ScriptList.Add(CalculatedList.Text);
-  CalculatedList.Free;
+    ScriptList.Add(');');
+    ScriptList.Add(CalculatedList.Text);
+  finally
+    CalculatedList.Free;
+  end;
 end;
 
 (***************  Script All Tables  ********************)
@@ -250,17 +252,20 @@ var
 begin
   TablesList:= TStringList.Create;
   TableScript:= TStringList.Create;
-  TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
-  List.Clear;
-  for i:= 0 to TablesList.Count - 1 do
-  begin
-    ScriptTableAsCreate(dbIndex, TablesList[i], TableScript);
-    List.Add('');
-    List.AddStrings(TableScript);
+  try
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    List.Clear;
+    for i:= 0 to TablesList.Count - 1 do
+    begin
+      ScriptTableAsCreate(dbIndex, TablesList[i], TableScript);
+      List.Add('');
+      List.AddStrings(TableScript);
+    end;
+    Result:= TablesList.Count > 0;
+  finally
+    TablesList.Free;
+    TableScript.Free;
   end;
-  Result:= TablesList.Count > 0;
-  TablesList.Free;
-  TableScript.Free;
 end;
 
 (********************  Script Procedure Template  ***********************)
@@ -276,21 +281,24 @@ var
 begin
   ProceduresList:= TStringList.Create;
   ProcedureScript:= TStringList.Create;
-  ProceduresList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 5, Count);
-  List.Clear;
-  for i:= 0 to ProceduresList.Count - 1 do
-  begin
-    ProcedureScript.Text:= fmMain.GetStoredProcBody(dbIndex, ProceduresList[i], SPOwner);
-    ProcedureScript.Insert(0, 'SET TERM ^ ;');
-    ProcedureScript.Insert(1, 'CREATE Procedure ' + ProceduresList[i] + '(');
-    ProcedureScript.Add('^');
-    ProcedureScript.Add('SET TERM ; ^');
-    ProcedureScript.Add('');
-    List.AddStrings(ProcedureScript);
+  try
+    ProceduresList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 5, Count);
+    List.Clear;
+    for i:= 0 to ProceduresList.Count - 1 do
+    begin
+      ProcedureScript.Text:= fmMain.GetStoredProcBody(dbIndex, ProceduresList[i], SPOwner);
+      ProcedureScript.Insert(0, 'SET TERM ^ ;');
+      ProcedureScript.Insert(1, 'CREATE Procedure ' + ProceduresList[i] + '(');
+      ProcedureScript.Add('^');
+      ProcedureScript.Add('SET TERM ; ^');
+      ProcedureScript.Add('');
+      List.AddStrings(ProcedureScript);
+    end;
+    Result:= ProceduresList.Count > 0;
+  finally
+    ProceduresList.Free;
+    ProcedureScript.Free;
   end;
-  Result:= ProceduresList.Count > 0;
-  ProceduresList.Free;
-  ProcedureScript.Free;
 end;
 
 (********************  Script Views   ***********************)
@@ -305,20 +313,23 @@ var
 begin
   ViewsList:= TStringList.Create;
   ViewsBodyList:= TStringList.Create;
-  ViewsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 4, Count);
-  List.Clear;
-  for i:= 0 to ViewsList.Count - 1 do
-  begin
-    fmMain.GetViewInfo(dbIndex, ViewsList[i], Columns, ViewBody);
-    ViewsBodyList.Text:= Trim(ViewBody);
-    List.Add('CREATE VIEW "' + ViewsList[i] + '" (' + Columns + ')');
-    List.Add('AS');
-    List.AddStrings(ViewsBodyList);
-    List.Add(' ;');
+  try
+    ViewsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 4, Count);
+    List.Clear;
+    for i:= 0 to ViewsList.Count - 1 do
+    begin
+      fmMain.GetViewInfo(dbIndex, ViewsList[i], Columns, ViewBody);
+      ViewsBodyList.Text:= Trim(ViewBody);
+      List.Add('CREATE VIEW "' + ViewsList[i] + '" (' + Columns + ')');
+      List.Add('AS');
+      List.AddStrings(ViewsBodyList);
+      List.Add(' ;');
+    end;
+    Result:= ViewsList.Count > 0;
+  finally
+    ViewsList.Free;
+    ViewsBodyList.Free;
   end;
-  Result:= ViewsList.Count > 0;
-  ViewsList.Free;
-  ViewsBodyList.Free;
 end;
 
 
@@ -333,18 +344,21 @@ var
 begin
   TriggersList:= TStringList.Create;
   TriggerScript:= TStringList.Create;
-  TriggersList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 3, Count);
-  List.Clear;
-  for i:= 0 to TriggersList.Count - 1 do
-  begin
-    TriggerScript.Clear;
-    dmSysTables.ScriptTrigger(dbIndex, TriggersList[i], TriggerScript, True);
-    List.AddStrings(TriggerScript);
-    List.Add('');
+  try
+    TriggersList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 3, Count);
+    List.Clear;
+    for i:= 0 to TriggersList.Count - 1 do
+    begin
+      TriggerScript.Clear;
+      dmSysTables.ScriptTrigger(dbIndex, TriggersList[i], TriggerScript, True);
+      List.AddStrings(TriggerScript);
+      List.Add('');
+    end;
+    Result:= TriggersList.Count > 0;
+  finally
+    TriggerScript.Free;
+    TriggersList.Free;
   end;
-  Result:= TriggersList.Count > 0;
-  TriggerScript.Free;
-  TriggersList.Free;
 end;
 
 (********************  Script Secondary indices  ***********************)
@@ -361,38 +375,41 @@ var
 begin
   TablesList:= TStringList.Create;
   FieldsList:= TStringList.Create;
-  TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
-  List.Clear;
-  for i:= 0 to TablesList.Count - 1 do
-  begin
-    PKName:= fmMain.GetPrimaryKeyIndexName(dbIndex, TablesList[i], ConstraintName);
-
-    if fmMain.GetIndices(TablesList[i], dmSysTables.sqQuery) then
-    with dmSysTables.sqQuery do
-    while not EOF do
+  try
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    List.Clear;
+    for i:= 0 to TablesList.Count - 1 do
     begin
-      if PKName <> Trim(FieldByName('RDB$Index_name').AsString) then
-      begin
-        Line:= 'create ';
-        if FieldByName('RDB$Unique_Flag').AsString = '1' then
-          Line:= Line + 'Unique ';
-        if FieldByName('RDB$Index_Type').AsString = '1' then
-          Line:= Line + 'Descending ';
-
-        Line:= Line + 'index ' + Trim(FieldByName('RDB$Index_name').AsString) + ' on ' + TablesList[i];
-
-        fmMain.GetIndexFields(TablesList[i], Trim(FieldByName('RDB$Index_Name').AsString), fmMain.SQLQuery1, FieldsList);
-        Line:= Line + ' (' + FieldsList.CommaText + ') ;';
-        List.Add(Line);
+      PKName:= fmMain.GetPrimaryKeyIndexName(dbIndex, TablesList[i], ConstraintName);
 
+      if fmMain.GetIndices(TablesList[i], dmSysTables.sqQuery) then
+      with dmSysTables.sqQuery do
+      while not EOF do
+      begin
+        if PKName <> Trim(FieldByName('RDB$Index_name').AsString) then
+        begin
+          Line:= 'create ';
+          if FieldByName('RDB$Unique_Flag').AsString = '1' then
+            Line:= Line + 'Unique ';
+          if FieldByName('RDB$Index_Type').AsString = '1' then
+            Line:= Line + 'Descending ';
+
+          Line:= Line + 'index ' + Trim(FieldByName('RDB$Index_name').AsString) + ' on ' + TablesList[i];
+
+          fmMain.GetIndexFields(TablesList[i], Trim(FieldByName('RDB$Index_Name').AsString), fmMain.SQLQuery1, FieldsList);
+          Line:= Line + ' (' + FieldsList.CommaText + ') ;';
+          List.Add(Line);
+
+        end;
+        Next;
       end;
-      Next;
     end;
+    dmSysTables.sqQuery.Close;
+    Result:= List.Count > 0;
+  finally
+    TablesList.Free;
+    FieldsList.Free;
   end;
-  dmSysTables.sqQuery.Close;
-  Result:= List.Count > 0;
-  TablesList.Free;
-  FieldsList.Free;
 end;
 
 
@@ -406,32 +423,35 @@ var
   Line: string;
 begin
   TablesList:= TStringList.Create;
-  TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
-  List.Clear;
-  for i:= 0 to TablesList.Count - 1 do
-  with dmSysTables do
-  begin
-    { to do: foreign keys are not picked up while FlameRobin does, e.g. this for employee.fdb:
-    ALTER TABLE EMPLOYEE ADD CONSTRAINT INTEG_28
-      FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT (DEPT_NO);
-    }
-    GetTableConstraints(TablesList[i], sqQuery);
-    while not sqQuery.EOF do
+  try
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    List.Clear;
+    for i:= 0 to TablesList.Count - 1 do
+    with dmSysTables do
     begin
-       Line:= 'alter table ' + TablesList[i] + ' add constraint ' + sqQuery.Fields[0].AsString +
-         ' foreign key (' + sqQuery.Fields[3].AsString + ') references ' +  sqQuery.Fields[4].AsString  +
-         ' (' + dmSysTables.GetConstraintForiegnKeyFields(sqQuery.Fields[5].AsString, fmMain.SQLQuery1) + ') ';
-       if Trim(sqQuery.Fields[6].AsString) <> 'RESTRICT' then
-         Line:= Line + ' on update ' + Trim(sqQuery.Fields[6].AsString);
-       if Trim(sqQuery.Fields[7].AsString) <> 'RESTRICT' then
-         Line:= Line + ' on delete ' + Trim(sqQuery.Fields[7].AsString);
-       List.Add(Line + ';');
-       sqQuery.Next;
+      { to do: foreign keys are not picked up while FlameRobin does, e.g. this for employee.fdb:
+      ALTER TABLE EMPLOYEE ADD CONSTRAINT INTEG_28
+        FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT (DEPT_NO);
+      }
+      GetTableConstraints(TablesList[i], sqQuery);
+      while not sqQuery.EOF do
+      begin
+         Line:= 'alter table ' + TablesList[i] + ' add constraint ' + sqQuery.Fields[0].AsString +
+           ' foreign key (' + sqQuery.Fields[3].AsString + ') references ' +  sqQuery.Fields[4].AsString  +
+           ' (' + dmSysTables.GetConstraintForiegnKeyFields(sqQuery.Fields[5].AsString, fmMain.SQLQuery1) + ') ';
+         if Trim(sqQuery.Fields[6].AsString) <> 'RESTRICT' then
+           Line:= Line + ' on update ' + Trim(sqQuery.Fields[6].AsString);
+         if Trim(sqQuery.Fields[7].AsString) <> 'RESTRICT' then
+           Line:= Line + ' on delete ' + Trim(sqQuery.Fields[7].AsString);
+         List.Add(Line + ';');
+         sqQuery.Next;
+      end;
+      sqQuery.Close;
     end;
-    sqQuery.Close;
+    Result:= List.Count > 0;
+  finally
+    TablesList.Free;
   end;
-  Result:= List.Count > 0;
-  TablesList.Free;
 end;
 
 
@@ -450,46 +470,47 @@ begin
     ObjName:= Copy(ObjName, 4, Length(ObjName) - 3);
     Permissions:= dmSysTables.GetObjectUserPermission(dbIndex, ObjName, UserName, ObjType);
     PermissionList:= TstringList.Create;
-    if Permissions <> '' then
-    begin
-      if Pos('<T>', OrigObjName) = 1 then // Table/View
+    try
+      if Permissions <> '' then
       begin
-        PermissionList.Clear;
-        if Pos('S', Permissions) > 0 then
-          PermissionList.Add('Select');
-
-        if Pos('U', Permissions) > 0 then
-          PermissionList.Add('Update');
-
-        if Pos('I', Permissions) > 0 then
-          PermissionList.Add('Insert');
-
-        if Pos('D', Permissions) > 0 then
-          PermissionList.Add('Delete');
-
-        if Pos('R', Permissions) > 0 then
-          PermissionList.Add('References');
-        Line:= 'Grant ' + PermissionList.CommaText + ' on ' + ObjName + ' to ' + NewUser;
-        if Pos('G', Permissions) > 0 then
-          Line:= Line + ' with Grant option';
-        List.Add(Line + ' ;');
-      end
-      else
-      if Pos('<P>', OrigObjName) = 1 then // Procedure
-        List.Add('Grant Execute on procedure ' + ObjName + ' to ' + NewUser + ' ;')
-      else
-      if Pos('<R>', OrigObjName) = 1 then // Role
-        List.Add('Grant ' + ObjName + ' to ' + NewUser + ' ;');
+        if Pos('<T>', OrigObjName) = 1 then // Table/View
+        begin
+          PermissionList.Clear;
+          if Pos('S', Permissions) > 0 then
+            PermissionList.Add('Select');
+
+          if Pos('U', Permissions) > 0 then
+            PermissionList.Add('Update');
+
+          if Pos('I', Permissions) > 0 then
+            PermissionList.Add('Insert');
+
+          if Pos('D', Permissions) > 0 then
+            PermissionList.Add('Delete');
+
+          if Pos('R', Permissions) > 0 then
+            PermissionList.Add('References');
+          Line:= 'Grant ' + PermissionList.CommaText + ' on ' + ObjName + ' to ' + NewUser;
+          if Pos('G', Permissions) > 0 then
+            Line:= Line + ' with Grant option';
+          List.Add(Line + ' ;');
+        end
+        else
+        if Pos('<P>', OrigObjName) = 1 then // Procedure
+          List.Add('Grant Execute on procedure ' + ObjName + ' to ' + NewUser + ' ;')
+        else
+        if Pos('<R>', OrigObjName) = 1 then // Role
+          List.Add('Grant ' + ObjName + ' to ' + NewUser + ' ;');
 
+      end;
+    finally
+      PermissionList.Free;
     end;
-    PermissionList.Free;
     Result:= True;
-
   except
-  on e: exception do
-    Result:= False;
+    on e: exception do
+      Result:= False;
   end;
-
 end;
 
 (********************  Script All Usesr and Rules permissions ***********************)
@@ -510,35 +531,37 @@ begin
   UsersList:= TStringList.Create;
   ObjectsList:= TStringList.Create;
   PermissionList:= TStringList.Create;
+  try
+    UsersList.CommaText:= dmSysTables.GetDBUsers(dbIndex);
+    List.Clear;
+    for i:= 0 to UsersList.Count - 1 do
+      if Pos('<R>', UsersList[i]) = 1 then
+        List.Add('/* Role ' + Copy(UsersList[i], 4, Length(UsersList[i]) - 3) + ' */')
+      else
+        List.Add('/* User ' + UsersList[i] + ' */');
 
-  UsersList.CommaText:= dmSysTables.GetDBUsers(dbIndex);
-  List.Clear;
-  for i:= 0 to UsersList.Count - 1 do
-    if Pos('<R>', UsersList[i]) = 1 then
-      List.Add('/* Role ' + Copy(UsersList[i], 4, Length(UsersList[i]) - 3) + ' */')
-    else
-      List.Add('/* User ' + UsersList[i] + ' */');
-
-  for i:= 0 to UsersList.Count - 1 do
-  begin
-    ObjectsList.CommaText:= dmSysTables.GetDBObjectsForPermissions(dbIndex);
-    if Pos('<R>', UsersList[i]) = 1 then
-      UserName:= Copy(UsersList[i], 4, Length(UsersList[i]) - 3)
-    else
-      UserName:= UsersList[i];
+    for i:= 0 to UsersList.Count - 1 do
+    begin
+      ObjectsList.CommaText:= dmSysTables.GetDBObjectsForPermissions(dbIndex);
+      if Pos('<R>', UsersList[i]) = 1 then
+        UserName:= Copy(UsersList[i], 4, Length(UsersList[i]) - 3)
+      else
+        UserName:= UsersList[i];
 
-    List.Add('');
-    List.Add('/* Permissions for: ' + UserName + ' */');
+      List.Add('');
+      List.Add('/* Permissions for: ' + UserName + ' */');
 
-    for j:= 0 to ObjectsList.Count - 1 do
-    begin
-      Result:= ScriptObjectPermission(dbIndex,  ObjectsList[j], UserName, ObjType, List);
+      for j:= 0 to ObjectsList.Count - 1 do
+      begin
+        Result:= ScriptObjectPermission(dbIndex,  ObjectsList[j], UserName, ObjType, List);
+      end;
     end;
+    Result:= UsersList.Count > 0;
+  finally
+    UsersList.Free;
+    ObjectsList.Free;
+    PermissionList.Free;
   end;
-  Result:= UsersList.Count > 0;
-  UsersList.Free;
-  ObjectsList.Free;
-  PermissionList.Free;
 end;
 
 (********************  Script One User or Rule permissions ***********************)
@@ -555,21 +578,23 @@ begin
     NewUser:= UserName;
   UsersList:= TStringList.Create;
   ObjectsList:= TStringList.Create;
+  try
+    UsersList.CommaText:= dmSysTables.GetDBUsers(dbIndex);
+    List.Clear;
 
-  UsersList.CommaText:= dmSysTables.GetDBUsers(dbIndex);
-  List.Clear;
-
-  ObjectsList.CommaText:= dmSysTables.GetDBObjectsForPermissions(dbIndex);
+    ObjectsList.CommaText:= dmSysTables.GetDBObjectsForPermissions(dbIndex);
 
-  List.Add('');
-  List.Add('/* Permissions for: ' + UserName + ' */');
+    List.Add('');
+    List.Add('/* Permissions for: ' + UserName + ' */');
 
-  for j:= 0 to ObjectsList.Count - 1 do
-    Result:= ScriptObjectPermission(dbIndex,  ObjectsList[j], UserName, ObjType, List, NewUser);
+    for j:= 0 to ObjectsList.Count - 1 do
+      Result:= ScriptObjectPermission(dbIndex,  ObjectsList[j], UserName, ObjType, List, NewUser);
 
-  Result:= UsersList.Count > 0;
-  UsersList.Free;
-  ObjectsList.Free;
+    Result:= UsersList.Count > 0;
+  finally
+    UsersList.Free;
+    ObjectsList.Free;
+  end;
 end;
 
 end.

+ 22 - 19
sqlhistory.pas

@@ -112,28 +112,31 @@ begin
     DBGrid1.Visible:= False;
     First;
     List:= TStringList.Create;
-    while not Eof do
-    begin
-      if (not cxAfterDate.Checked) or (FieldByName('Time').AsDateTime > DateEdit1.Date) then
+    try
+      while not Eof do
       begin
-        CurrType:= FieldByName('SQLType').AsString;
-        if (cbSQLType.ItemIndex = 0) or
-          ((CurrType = 'DDL') and (cbSQLType.ItemIndex in [1, 2])) or
-          ((CurrType = 'DML') and (cbSQLType.ItemIndex in [1, 3])) or
-          ((CurrType = 'SELECT') and (cbSQLType.ItemIndex = 4)) then
-          begin
-            List.Add('-- ' + FieldByName('Time').AsString);
-            Line:= FieldByName('SQLStatement').AsString;
-            if Pos(';', Line) = 0 then
-              Line:= Line + ';';
-            List.Add(Line);
-          end;
-
+        if (not cxAfterDate.Checked) or (FieldByName('Time').AsDateTime > DateEdit1.Date) then
+        begin
+          CurrType:= FieldByName('SQLType').AsString;
+          if (cbSQLType.ItemIndex = 0) or
+            ((CurrType = 'DDL') and (cbSQLType.ItemIndex in [1, 2])) or
+            ((CurrType = 'DML') and (cbSQLType.ItemIndex in [1, 3])) or
+            ((CurrType = 'SELECT') and (cbSQLType.ItemIndex = 4)) then
+            begin
+              List.Add('-- ' + FieldByName('Time').AsString);
+              Line:= FieldByName('SQLStatement').AsString;
+              if Pos(';', Line) = 0 then
+                Line:= Line + ';';
+              List.Add(Line);
+            end;
+
+        end;
+        Next;
       end;
-      Next;
+      List.SaveToFile(SaveDialog1.FileName);
+    finally
+      List.Free;
     end;
-    List.SaveToFile(SaveDialog1.FileName);
-    List.Free;
     DBGrid1.Visible:= True;
   end;
 end;

+ 85 - 76
tablemanage.pas

@@ -159,10 +159,13 @@ begin
   if sgTriggers.RowCount > 1 then
   begin
     List:= TStringList.Create;
-    ATriggerName:= sgTriggers.Cells[0, sgTriggers.Row];
-    dmSysTables.ScriptTrigger(fdbIndex, ATriggerName, List);
-    fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Trigger ', List.Text, bbRefreshTriggers.OnClick);
-    List.Free;
+    try
+      ATriggerName:= sgTriggers.Cells[0, sgTriggers.Row];
+      dmSysTables.ScriptTrigger(fdbIndex, ATriggerName, List);
+      fmMain.ShowCompleteQueryWindow(fdbIndex, 'Edit Trigger ', List.Text, bbRefreshTriggers.OnClick);
+    finally
+      List.Free;
+    end;
   end;
 
 end;
@@ -297,10 +300,13 @@ var
 begin
   // Get current fields
   FieldsList:= TStringList.Create;
-  fmMain.GetFields(fdbIndex, fTableName, FieldsList);
-  fmNewConstraint.clxOnFields.Clear;
-  fmNewConstraint.clxOnFields.Items.AddStrings(FieldsList);
-  FieldsList.Free;
+  try
+    fmMain.GetFields(fdbIndex, fTableName, FieldsList);
+    fmNewConstraint.clxOnFields.Clear;
+    fmNewConstraint.clxOnFields.Items.AddStrings(FieldsList);
+  finally
+    FieldsList.Free;
+  end;
   fmMain.SQLQuery1.Close;
   fmNewConstraint.edNewName.Text:= 'FK_' + fTableName + '_' + IntToStr(sgConstraints.RowCount);
 
@@ -497,75 +503,78 @@ var
 begin
   sqlTrans.Commit;
   UsersList:= TStringList.Create;
-  UsersList.CommaText:= dmSysTables.GetDBUsers(fdbIndex, fTableName);
-  sgPermissions.RowCount:= UsersList.Count + 1;
-  for i:= 0 to UsersList.Count - 1 do
-  begin
-    UserName:= UsersList[i];
-    if Pos('<R>', UserName) = 1 then
-      begin
-        sgPermissions.Cells[1, i + 1]:= 'Role';
-        Delete(UserName, 1, 3);
-      end
-    else
-      sgPermissions.Cells[1, i + 1]:= 'User';
-
-    sgPermissions.Cells[0, i + 1]:= UserName;
-
-    // Permissions
-    Permissions:= dmSysTables.GetObjectUserPermission(fdbIndex, fTableName, UserName, ObjType);
-
-    if Pos('S', Permissions) > 0 then
-      sgPermissions.Cells[2, i + 1]:= '1'
-    else
-      sgPermissions.Cells[2, i + 1]:= '0';
-
-    if Pos('I', Permissions) > 0 then
-      sgPermissions.Cells[3, i + 1]:= '1'
-    else
-      sgPermissions.Cells[3, i + 1]:= '0';
-
-    if Pos('U', Permissions) > 0 then
-      sgPermissions.Cells[4, i + 1]:= '1'
-    else
-      sgPermissions.Cells[4, i + 1]:= '0';
-
-    if Pos('D', Permissions) > 0 then
-      sgPermissions.Cells[5, i + 1]:= '1'
-    else
-      sgPermissions.Cells[5, i + 1]:= '0';
-
-    if Pos('R', Permissions) > 0 then
-      sgPermissions.Cells[6, i + 1]:= '1'
-    else
-      sgPermissions.Cells[6, i + 1]:= '0';
-
-    if Pos('SG', Permissions) > 0 then
-      sgPermissions.Cells[7, i + 1]:= '1'
-    else
-      sgPermissions.Cells[7, i + 1]:= '0';
-
-    if Pos('IG', Permissions) > 0 then
-      sgPermissions.Cells[8, i + 1]:= '1'
-    else
-      sgPermissions.Cells[8, i + 1]:= '0';
-
-    if Pos('UG', Permissions) > 0 then
-      sgPermissions.Cells[9, i + 1]:= '1'
-    else
-      sgPermissions.Cells[9, i + 1]:= '0';
-
-    if Pos('DG', Permissions) > 0 then
-      sgPermissions.Cells[10, i + 1]:= '1'
-    else
-      sgPermissions.Cells[10, i + 1]:= '0';
-
-    if Pos('RG', Permissions) > 0 then
-      sgPermissions.Cells[11, i + 1]:= '1'
-    else
-      sgPermissions.Cells[11, i + 1]:= '0';
+  try
+    UsersList.CommaText:= dmSysTables.GetDBUsers(fdbIndex, fTableName);
+    sgPermissions.RowCount:= UsersList.Count + 1;
+    for i:= 0 to UsersList.Count - 1 do
+    begin
+      UserName:= UsersList[i];
+      if Pos('<R>', UserName) = 1 then
+        begin
+          sgPermissions.Cells[1, i + 1]:= 'Role';
+          Delete(UserName, 1, 3);
+        end
+      else
+        sgPermissions.Cells[1, i + 1]:= 'User';
+
+      sgPermissions.Cells[0, i + 1]:= UserName;
+
+      // Permissions
+      Permissions:= dmSysTables.GetObjectUserPermission(fdbIndex, fTableName, UserName, ObjType);
+
+      if Pos('S', Permissions) > 0 then
+        sgPermissions.Cells[2, i + 1]:= '1'
+      else
+        sgPermissions.Cells[2, i + 1]:= '0';
+
+      if Pos('I', Permissions) > 0 then
+        sgPermissions.Cells[3, i + 1]:= '1'
+      else
+        sgPermissions.Cells[3, i + 1]:= '0';
+
+      if Pos('U', Permissions) > 0 then
+        sgPermissions.Cells[4, i + 1]:= '1'
+      else
+        sgPermissions.Cells[4, i + 1]:= '0';
+
+      if Pos('D', Permissions) > 0 then
+        sgPermissions.Cells[5, i + 1]:= '1'
+      else
+        sgPermissions.Cells[5, i + 1]:= '0';
+
+      if Pos('R', Permissions) > 0 then
+        sgPermissions.Cells[6, i + 1]:= '1'
+      else
+        sgPermissions.Cells[6, i + 1]:= '0';
+
+      if Pos('SG', Permissions) > 0 then
+        sgPermissions.Cells[7, i + 1]:= '1'
+      else
+        sgPermissions.Cells[7, i + 1]:= '0';
+
+      if Pos('IG', Permissions) > 0 then
+        sgPermissions.Cells[8, i + 1]:= '1'
+      else
+        sgPermissions.Cells[8, i + 1]:= '0';
+
+      if Pos('UG', Permissions) > 0 then
+        sgPermissions.Cells[9, i + 1]:= '1'
+      else
+        sgPermissions.Cells[9, i + 1]:= '0';
+
+      if Pos('DG', Permissions) > 0 then
+        sgPermissions.Cells[10, i + 1]:= '1'
+      else
+        sgPermissions.Cells[10, i + 1]:= '0';
+
+      if Pos('RG', Permissions) > 0 then
+        sgPermissions.Cells[11, i + 1]:= '1'
+      else
+        sgPermissions.Cells[11, i + 1]:= '0';
+    end;
+  finally
+    UsersList.Free;
   end;
-  UsersList.Free;
 end;
 
 initialization

+ 20 - 20
update.lfm

@@ -10,12 +10,12 @@ object fmUpdate: TfmUpdate
   OnActivate = FormActivate
   OnClose = FormClose
   Position = poScreenCenter
-  LCLVersion = '1.0.14.0'
+  LCLVersion = '1.2.0.3'
   object Label1: TLabel
     Left = 8
-    Height = 18
+    Height = 13
     Top = 32
-    Width = 104
+    Width = 75
     BidiMode = bdRightToLeft
     Caption = 'Current version'
     ParentBidiMode = False
@@ -64,9 +64,9 @@ object fmUpdate: TfmUpdate
   end
   object cxProxy: TCheckBox
     Left = 16
-    Height = 24
+    Height = 17
     Top = 176
-    Width = 177
+    Width = 130
     Caption = 'connect through proxy'
     OnChange = cxProxyChange
     ParentBidiMode = False
@@ -77,38 +77,38 @@ object fmUpdate: TfmUpdate
     Height = 108
     Top = 198
     Width = 472
-    ClientHeight = 104
+    ClientHeight = 90
     ClientWidth = 468
     TabOrder = 5
     Visible = False
     object Label2: TLabel
       Left = 6
-      Height = 18
+      Height = 13
       Top = 11
-      Width = 85
+      Width = 62
       Alignment = taRightJustify
       Caption = 'Proxy server'
       ParentColor = False
     end
     object edProxy: TEdit
       Left = 103
-      Height = 27
+      Height = 21
       Top = 8
       Width = 112
       TabOrder = 0
     end
     object Label3: TLabel
       Left = 7
-      Height = 18
+      Height = 13
       Top = 41
-      Width = 73
+      Width = 51
       Alignment = taRightJustify
       Caption = 'Proxy port'
       ParentColor = False
     end
     object edPort: TEdit
       Left = 103
-      Height = 27
+      Height = 21
       Top = 40
       Width = 69
       TabOrder = 1
@@ -116,32 +116,32 @@ object fmUpdate: TfmUpdate
     end
     object Label4: TLabel
       Left = 6
-      Height = 18
+      Height = 13
       Top = 80
-      Width = 32
+      Width = 22
       Alignment = taRightJustify
       Caption = 'User'
       ParentColor = False
     end
     object edUser: TEdit
       Left = 335
-      Height = 27
+      Height = 21
       Top = 71
       Width = 112
       TabOrder = 2
     end
     object Label5: TLabel
       Left = 247
-      Height = 18
+      Height = 13
       Top = 80
-      Width = 67
+      Width = 46
       Alignment = taRightJustify
       Caption = 'Password'
       ParentColor = False
     end
     object edPassword: TEdit
       Left = 103
-      Height = 27
+      Height = 21
       Top = 71
       Width = 112
       EchoMode = emPassword
@@ -163,9 +163,9 @@ object fmUpdate: TfmUpdate
   end
   object laTime: TLabel
     Left = 408
-    Height = 27
+    Height = 24
     Top = 104
-    Width = 66
+    Width = 54
     Caption = '00:00'
     Color = clCream
     Font.Color = clRed

+ 21 - 19
update.lrs

@@ -1,43 +1,45 @@
+{ This is an automatically generated lazarus resource file }
+
 LazarusResources.Add('TfmUpdate','FORMDATA',[
   'TPF0'#9'TfmUpdate'#8'fmUpdate'#4'Left'#3'K'#2#6'Height'#3':'#1#3'Top'#3#9#1#5
   +'Width'#3#245#1#11'BorderStyle'#7#8'bsDialog'#7'Caption'#6#14'Version update'
   +#12'ClientHeight'#3':'#1#11'ClientWidth'#3#245#1#10'OnActivate'#7#12'FormAct'
   +'ivate'#7'OnClose'#7#9'FormClose'#8'Position'#7#14'poScreenCenter'#10'LCLVer'
-  +'sion'#6#8'1.0.14.0'#0#6'TLabel'#6'Label1'#4'Left'#2#8#6'Height'#2#18#3'Top'
-  +#2' '#5'Width'#2'h'#8'BidiMode'#7#13'bdRightToLeft'#7'Caption'#6#15'Current '
-  +'version'#14'ParentBidiMode'#8#11'ParentColor'#8#0#0#11'TStaticText'#9'stVer'
-  +'sion'#4'Left'#3#152#0#6'Height'#2#19#3'Top'#2' '#5'Width'#3#148#0#7'Caption'
-  +#6#9'stVersion'#5'Color'#7#7'clWhite'#11'ParentColor'#8#8'TabOrder'#2#0#11'T'
-  +'ransparent'#8#0#0#7'TBitBtn'#8'bbSearch'#4'Left'#2#8#6'Height'#2#30#3'Top'#2
+  +'sion'#6#7'1.2.0.3'#0#6'TLabel'#6'Label1'#4'Left'#2#8#6'Height'#2#13#3'Top'#2
+  +' '#5'Width'#2'K'#8'BidiMode'#7#13'bdRightToLeft'#7'Caption'#6#15'Current ve'
+  +'rsion'#14'ParentBidiMode'#8#11'ParentColor'#8#0#0#11'TStaticText'#9'stVersi'
+  +'on'#4'Left'#3#152#0#6'Height'#2#19#3'Top'#2' '#5'Width'#3#148#0#7'Caption'#6
+  +#9'stVersion'#5'Color'#7#7'clWhite'#11'ParentColor'#8#8'TabOrder'#2#0#11'Tra'
+  +'nsparent'#8#0#0#7'TBitBtn'#8'bbSearch'#4'Left'#2#8#6'Height'#2#30#3'Top'#2
   +'H'#5'Width'#2'K'#7'Caption'#6#5'Check'#7'OnClick'#7#13'bbSearchClick'#8'Tab'
   +'Order'#2#1#0#0#11'TStaticText'#12'stNewVersion'#4'Left'#3#152#0#6'Height'#2
   +#23#3'Top'#2'H'#5'Width'#3#196#0#7'Caption'#6#1'-'#5'Color'#7#7'clWhite'#11
   +'ParentColor'#8#8'TabOrder'#2#2#11'Transparent'#8#0#0#7'TBitBtn'#10'bbDownlo'
   +'ad'#4'Left'#2#8#6'Height'#2#30#3'Top'#2'p'#5'Width'#3#148#0#7'Caption'#6#14
   +'Install Update'#7'OnClick'#7#15'bbDownloadClick'#8'TabOrder'#2#3#7'Visible'
-  +#8#0#0#9'TCheckBox'#7'cxProxy'#4'Left'#2#16#6'Height'#2#24#3'Top'#3#176#0#5
-  +'Width'#3#177#0#7'Caption'#6#21'connect through proxy'#8'OnChange'#7#13'cxPr'
+  +#8#0#0#9'TCheckBox'#7'cxProxy'#4'Left'#2#16#6'Height'#2#17#3'Top'#3#176#0#5
+  +'Width'#3#130#0#7'Caption'#6#21'connect through proxy'#8'OnChange'#7#13'cxPr'
   +'oxyChange'#14'ParentBidiMode'#8#8'TabOrder'#2#4#0#0#9'TGroupBox'#9'GroupBox'
   +'1'#4'Left'#2#15#6'Height'#2'l'#3'Top'#3#198#0#5'Width'#3#216#1#12'ClientHei'
-  +'ght'#2'h'#11'ClientWidth'#3#212#1#8'TabOrder'#2#5#7'Visible'#8#0#6'TLabel'#6
-  +'Label2'#4'Left'#2#6#6'Height'#2#18#3'Top'#2#11#5'Width'#2'U'#9'Alignment'#7
+  +'ght'#2'Z'#11'ClientWidth'#3#212#1#8'TabOrder'#2#5#7'Visible'#8#0#6'TLabel'#6
+  +'Label2'#4'Left'#2#6#6'Height'#2#13#3'Top'#2#11#5'Width'#2'>'#9'Alignment'#7
   +#14'taRightJustify'#7'Caption'#6#12'Proxy server'#11'ParentColor'#8#0#0#5'TE'
-  +'dit'#7'edProxy'#4'Left'#2'g'#6'Height'#2#27#3'Top'#2#8#5'Width'#2'p'#8'TabO'
-  +'rder'#2#0#0#0#6'TLabel'#6'Label3'#4'Left'#2#7#6'Height'#2#18#3'Top'#2')'#5
-  +'Width'#2'I'#9'Alignment'#7#14'taRightJustify'#7'Caption'#6#10'Proxy port'#11
-  +'ParentColor'#8#0#0#5'TEdit'#6'edPort'#4'Left'#2'g'#6'Height'#2#27#3'Top'#2
+  +'dit'#7'edProxy'#4'Left'#2'g'#6'Height'#2#21#3'Top'#2#8#5'Width'#2'p'#8'TabO'
+  +'rder'#2#0#0#0#6'TLabel'#6'Label3'#4'Left'#2#7#6'Height'#2#13#3'Top'#2')'#5
+  +'Width'#2'3'#9'Alignment'#7#14'taRightJustify'#7'Caption'#6#10'Proxy port'#11
+  +'ParentColor'#8#0#0#5'TEdit'#6'edPort'#4'Left'#2'g'#6'Height'#2#21#3'Top'#2
   +'('#5'Width'#2'E'#8'TabOrder'#2#1#4'Text'#6#4'8080'#0#0#6'TLabel'#6'Label4'#4
-  +'Left'#2#6#6'Height'#2#18#3'Top'#2'P'#5'Width'#2' '#9'Alignment'#7#14'taRigh'
+  +'Left'#2#6#6'Height'#2#13#3'Top'#2'P'#5'Width'#2#22#9'Alignment'#7#14'taRigh'
   +'tJustify'#7'Caption'#6#4'User'#11'ParentColor'#8#0#0#5'TEdit'#6'edUser'#4'L'
-  +'eft'#3'O'#1#6'Height'#2#27#3'Top'#2'G'#5'Width'#2'p'#8'TabOrder'#2#2#0#0#6
-  +'TLabel'#6'Label5'#4'Left'#3#247#0#6'Height'#2#18#3'Top'#2'P'#5'Width'#2'C'#9
+  +'eft'#3'O'#1#6'Height'#2#21#3'Top'#2'G'#5'Width'#2'p'#8'TabOrder'#2#2#0#0#6
+  +'TLabel'#6'Label5'#4'Left'#3#247#0#6'Height'#2#13#3'Top'#2'P'#5'Width'#2'.'#9
   +'Alignment'#7#14'taRightJustify'#7'Caption'#6#8'Password'#11'ParentColor'#8#0
-  +#0#5'TEdit'#10'edPassword'#4'Left'#2'g'#6'Height'#2#27#3'Top'#2'G'#5'Width'#2
+  +#0#5'TEdit'#10'edPassword'#4'Left'#2'g'#6'Height'#2#21#3'Top'#2'G'#5'Width'#2
   +'p'#8'EchoMode'#7#10'emPassword'#12'PasswordChar'#6#1'*'#8'TabOrder'#2#3#0#0
   +#0#11'TStaticText'#8'stStatus'#4'Left'#2#8#6'Height'#2#28#3'Top'#3#146#0#5'W'
   +'idth'#3#223#1#9'Alignment'#7#8'taCenter'#7'Caption'#6#1'-'#5'Color'#7#7'clW'
   +'hite'#11'ParentColor'#8#8'TabOrder'#2#6#11'Transparent'#8#0#0#6'TLabel'#6'l'
-  +'aTime'#4'Left'#3#152#1#6'Height'#2#27#3'Top'#2'h'#5'Width'#2'B'#7'Caption'#6
+  +'aTime'#4'Left'#3#152#1#6'Height'#2#24#3'Top'#2'h'#5'Width'#2'6'#7'Caption'#6
   +#5'00:00'#5'Color'#7#7'clCream'#10'Font.Color'#7#5'clRed'#11'Font.Height'#2
   +#235#9'Font.Name'#6#16'Courier 10 Pitch'#11'ParentColor'#8#10'ParentFont'#8
   +#11'Transparent'#8#7'Visible'#8#0#0#8'TProcess'#8'Process1'#6'Active'#8#7'Op'

+ 67 - 62
update.pas

@@ -116,37 +116,40 @@ var
 begin
   try
     http:= THTTPSend.Create;
-
-    with fmUpdate do
-    if cxProxy.Checked then
-    begin
-      http.ProxyHost:= edProxy.Text;
-      http.ProxyPort:= edPort.Text;
-      http.ProxyUser:= edUser.Text;
-      http.ProxyPass:= edPassword.Text;
+    try
+      with fmUpdate do
+      if cxProxy.Checked then
+      begin
+        http.ProxyHost:= edProxy.Text;
+        http.ProxyPort:= edPort.Text;
+        http.ProxyUser:= edUser.Text;
+        http.ProxyPass:= edPassword.Text;
+      end;
+
+      fSuccess:= http.HTTPMethod('GET', fURL);
+      if fSuccess then
+      if http.Document.Size > 10000 then  // Actual file has been downloaded
+        http.Document.SaveToFile(ExtractFilePath(ParamStr(0)) + fFileName)
+      else
+      begin // Error HTML response
+        List:= TStringList.Create;
+        try
+          List.LoadFromStream(http.Document);
+          fSuccess:= False;
+          fErrorMessage:= List.Text;
+        finally
+          List.Free;
+        end;
+      end;
+    finally
+      http.Free
     end;
-
-    fSuccess:= http.HTTPMethod('GET', fURL);
-    if fSuccess then
-    if http.Document.Size > 10000 then  // Actual file has been downloaded
-      http.Document.SaveToFile(ExtractFilePath(ParamStr(0)) + fFileName)
-    else
-    begin // Error HTML response
-      List:= TStringList.Create;
-      List.LoadFromStream(http.Document);
+  except
+    on e: exception do
+    begin
       fSuccess:= False;
-      fErrorMessage:= List.Text;
-      List.Free;
+      fErrorMessage:= e.Message;
     end;
-
-    http.Free
-
-  except
-  on e: exception do
-  begin
-    fSuccess:= False;
-    fErrorMessage:= e.Message;
-  end;
   end;
 
 end;
@@ -262,44 +265,46 @@ var
   ServerMinor: Word;
   VerStr: string;
 begin
-  List:= TStringList.Create;
-
-  OS:= Target + Arch + '-';
   try
-    http:= THTTPSend.Create;
-
-    if cxProxy.Checked then
-    begin
-      http.ProxyHost:= edProxy.Text;
-      http.ProxyPort:= edPort.Text;
-      http.ProxyUser:= edUser.Text;
-      http.ProxyPass:= edPassword.Text;
+    List:= TStringList.Create;
+    try
+      OS:= Target + Arch + '-';
+        http:= THTTPSend.Create;
+        try
+          if cxProxy.Checked then
+          begin
+            http.ProxyHost:= edProxy.Text;
+            http.ProxyPort:= edPort.Text;
+            http.ProxyUser:= edUser.Text;
+            http.ProxyPass:= edPassword.Text;
+          end;
+
+          http.HTTPMethod('GET', 'http://code-sd.com/turbobird/releases/' + OS + IntToStr(Major));
+          // Linux64-0
+          List.LoadFromStream(http.Document);
+          VerStr:= Trim(List.Text);
+          ServerMinor:= StrToInt(Copy(VerStr, 1, Pos('.', VerStr) - 1));
+          Delete(VerStr, 1, Pos('.', VerStr));
+          ServerRelease:= StrToInt(VerStr);
+          NewVersion:= (Minor < ServerMinor) or (ServerRelease > ReleaseVersion);
+
+          Version:= IntToStr(Major) + '.' + IntToStr(ServerMinor) + '.' + IntToStr(ServerRelease);
+          AFileName:= 'TurboBird-' + OS + IntToStr(Major) + '.zip';
+          // TurboBird-Linux32-1.zip
+          Result:= True;
+        finally
+          http.free;
+        end;
+    finally
+      List.Free;
     end;
-
-    http.HTTPMethod('GET', 'http://code-sd.com/turbobird/releases/' + OS + IntToStr(Major));
-    // Linux64-0
-    List.LoadFromStream(http.Document);
-    VerStr:= Trim(List.Text);
-    ServerMinor:= StrToInt(Copy(VerStr, 1, Pos('.', VerStr) - 1));
-    Delete(VerStr, 1, Pos('.', VerStr));
-    ServerRelease:= StrToInt(VerStr);
-    NewVersion:= (Minor < ServerMinor) or (ServerRelease > ReleaseVersion);
-
-    Version:= IntToStr(Major) + '.' + IntToStr(ServerMinor) + '.' + IntToStr(ServerRelease);
-    AFileName:= 'TurboBird-' + OS + IntToStr(Major) + '.zip';
-    // TurboBird-Linux32-1.zip
-    Result:= True;
-    List.Free;
-    http.Free
-
   except
-  on e: exception do
-  begin
-    Result:= False;
-    ResMsg:= e.Message;
-  end;
+    on e: exception do
+    begin
+      Result:= False;
+      ResMsg:= e.Message;
+    end;
   end;
-
 end;
 
 function TfmUpdate.DownloadNewVersion: Boolean;

Some files were not shown because too many files changed in this diff