Преглед изворни кода

Edit fields: wait until combobox editingdone before validation/updating other gui controls. Backup: prepare for .zip functionality selecting files

Reinier Olislagers пре 11 година
родитељ
комит
1d756eb3d2
6 измењених фајлова са 66 додато и 53 уклоњено
  1. 14 10
      backuprestore.lfm
  2. 7 3
      backuprestore.pas
  3. 2 2
      neweditfield.lfm
  4. 31 31
      neweditfield.lrs
  5. 6 4
      neweditfield.pas
  6. 6 3
      unitfirebirdservices.pas

+ 14 - 10
backuprestore.lfm

@@ -1,20 +1,20 @@
 object fmBackupRestore: TfmBackupRestore
   Left = 402
-  Height = 445
-  Top = 201
+  Height = 550
+  Top = 154
   Width = 496
-  Caption = 'Backup/Resore database'
-  ClientHeight = 445
+  Caption = 'Backup/Restore database'
+  ClientHeight = 550
   ClientWidth = 496
   Position = poScreenCenter
   LCLVersion = '1.2.2.0'
   object GroupBox1: TGroupBox
     Left = 0
-    Height = 288
+    Height = 328
     Top = 0
     Width = 496
     Align = alTop
-    ClientHeight = 270
+    ClientHeight = 310
     ClientWidth = 492
     Color = clWhite
     ParentColor = False
@@ -345,13 +345,17 @@ object fmBackupRestore: TfmBackupRestore
     TabOrder = 1
   end
   object OpenDialog1: TOpenDialog
-    left = 456
-    top = 104
+    Filter = '*.fbk, *.fbk.zip|*.fbk;*.fbk.zip|*|*'
+    FilterIndex = 0
+    left = 16
+    top = 272
   end
   object SaveDialog1: TSaveDialog
     DefaultExt = '.fbk'
+    Filter = '*.fbk.zip|*.fbk.zip|*.fbk|*.fbk|*|*'
+    FilterIndex = 0
     Options = [ofOverwritePrompt, ofEnableSizing, ofViewDetail]
-    left = 456
-    top = 176
+    left = 104
+    top = 272
   end
 end

+ 7 - 3
backuprestore.pas

@@ -59,12 +59,11 @@ begin
   if ((cbOperation.ItemIndex = 0) and (SaveDialog1.Execute)) or
    ((cbOperation.ItemIndex = 1) and (OpenDialog1.Execute)) then
   begin
-    if cbOperation.ItemIndex = 0 then
+    if cbOperation.ItemIndex = 0 then //backup
       edBackup.Text:= SaveDialog1.FileName
-    else
+    else //restore
       edBackup.Text:= OpenDialog1.FileName;
   end;
-
 end;
 
 procedure TfmBackupRestore.Init(Title, Database, User, Password: string);
@@ -82,7 +81,12 @@ begin
   end
   else
   begin
+    // Assume local host for *nix, embedded for Windows
+    {$IFDEF MSWINDOWS}
+    edHost.Text := '';
+    {$ELSE}
     edHost.Text := 'localhost';
+    {$ENDIF}
     edTargetDatabase.Text := FDatabase;
   end;
 end;

+ 2 - 2
neweditfield.lfm

@@ -70,7 +70,7 @@ object fmNewEditField: TfmNewEditField
     AutoCompleteText = [cbactEnabled, cbactEndOfLineComplete, cbactSearchAscending]
     Color = 16249563
     ItemHeight = 13
-    OnChange = cbTypeChange
+    OnEditingDone = cbTypeEditingDone
     ParentShowHint = False
     ShowHint = True
     Style = csDropDownList
@@ -166,7 +166,7 @@ object fmNewEditField: TfmNewEditField
     Width = 124
     Enabled = False
     ItemHeight = 13
-    OnChange = cbCharsetChange
+    OnEditingDone = cbCharsetEditingDone
     TabOrder = 8
   end
   object lblCharset: TLabel

+ 31 - 31
neweditfield.lrs

@@ -19,35 +19,35 @@ LazarusResources.Add('TfmNewEditField','FORMDATA',[
   +'Box'#6'cbType'#4'Left'#2'e'#6'Height'#2#21#4'Hint'#6#24'Data type for this '
   +'field'#3'Top'#2'('#5'Width'#3#139#0#12'AutoComplete'#9#16'AutoCompleteText'
   +#11#12'cbactEnabled'#22'cbactEndOfLineComplete'#20'cbactSearchAscending'#0#5
-  +'Color'#4#219#242#247#0#10'ItemHeight'#2#13#8'OnChange'#7#12'cbTypeChange'#14
-  +'ParentShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8'TabOrder'#2
-  +#1#0#0#9'TSpinEdit'#6'seSize'#4'Left'#2'e'#6'Height'#2#21#4'Hint'#6'=Size of'
-  +' field. For text fields: size in characters, not bytes'#3'Top'#2'M'#5'Width'
-  +#2'2'#8'MaxValue'#3#16''''#14'ParentShowHint'#8#8'ShowHint'#9#8'TabOrder'#2#2
-  +#0#0#9'TCheckBox'#11'cxAllowNull'#4'Left'#2#8#6'Height'#2#17#3'Top'#3#152#0#5
-  +'Width'#2'A'#7'Caption'#6#10'Allow Null'#7'Checked'#9#5'State'#7#9'cbChecked'
-  +#8'TabOrder'#2#5#0#0#7'TBitBtn'#5'bbAdd'#4'Left'#3#230#0#6'Height'#2#30#3'To'
-  +'p'#3'y'#1#5'Width'#2'K'#7'Caption'#6#3'Add'#5'Color'#4#219#242#247#0#7'OnCl'
-  +'ick'#7#10'bbAddClick'#8'TabOrder'#2#6#0#0#9'TSpinEdit'#7'seOrder'#4'Left'#2
-  +'e'#6'Height'#2#21#3'Top'#2'p'#5'Width'#2'2'#8'MaxValue'#3#16''''#8'TabOrder'
-  +#2#4#5'Value'#2#1#0#0#5'TEdit'#9'edDefault'#4'Left'#2'e'#6'Height'#2#21#3'To'
-  +'p'#3#186#0#5'Width'#3#204#0#8'TabOrder'#2#7#0#0#6'TLabel'#6'Label6'#4'Left'
-  +#2#8#6'Height'#2#13#3'Top'#3'A'#1#5'Width'#2'N'#7'Caption'#6#17'Field Descri'
-  +'ption'#11'ParentColor'#8#0#0#5'TEdit'#13'edDescription'#4'Left'#2#8#6'Heigh'
-  +'t'#2#21#3'Top'#3'S'#1#5'Width'#3')'#1#8'TabOrder'#2#10#0#0#6'TLabel'#6'Labe'
-  +'l7'#4'Left'#3#168#0#6'Height'#2#13#3'Top'#2'Q'#5'Width'#2#25#7'Caption'#6#5
-  +'Scale'#11'ParentColor'#8#0#0#9'TSpinEdit'#7'seScale'#4'Left'#3#208#0#6'Heig'
-  +'ht'#2#21#4'Hint'#6'0Sets decimal scale for numeric/decimal datatypes'#3'Top'
-  +#2'M'#5'Width'#2'2'#7'Enabled'#8#8'MaxValue'#2#18#14'ParentShowHint'#8#8'Sho'
-  +'wHint'#9#8'TabOrder'#2#3#0#0#9'TComboBox'#9'cbCharset'#4'Left'#2'e'#6'Heigh'
-  +'t'#2#21#4'Hint'#6'@New field character setIF IT DIFFERS from database chara'
-  +'cter set'#3'Top'#3#224#0#5'Width'#2'|'#7'Enabled'#8#10'ItemHeight'#2#13#8'O'
-  +'nChange'#7#15'cbCharsetChange'#8'TabOrder'#2#8#0#0#6'TLabel'#10'lblCharset'
-  +#4'Left'#2#8#6'Height'#2#13#3'Top'#3#228#0#5'Width'#2'&'#7'Caption'#6#7'Char'
-  +'set'#11'ParentColor'#8#0#0#6'TLabel'#12'lblCollation'#4'Left'#2#8#6'Height'
-  +#2#13#3'Top'#3#12#1#5'Width'#2')'#7'Caption'#6#9'Collation'#11'ParentColor'#8
-  +#0#0#9'TComboBox'#11'cbCollation'#4'Left'#2'e'#6'Height'#2#21#4'Hint'#6'<Col'
-  +'lation of new field IF IT DIFFERS from database collation'#3'Top'#3#8#1#5'W'
-  +'idth'#2'|'#7'Enabled'#8#10'ItemHeight'#2#13#14'ParentShowHint'#8#8'ShowHint'
-  +#9#8'TabOrder'#2#9#0#0#0
+  +'Color'#4#219#242#247#0#10'ItemHeight'#2#13#13'OnEditingDone'#7#17'cbTypeEdi'
+  +'tingDone'#14'ParentShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8
+  +'TabOrder'#2#1#0#0#9'TSpinEdit'#6'seSize'#4'Left'#2'e'#6'Height'#2#21#4'Hint'
+  +#6'=Size of field. For text fields: size in characters, not bytes'#3'Top'#2
+  +'M'#5'Width'#2'2'#8'MaxValue'#3#16''''#14'ParentShowHint'#8#8'ShowHint'#9#8
+  +'TabOrder'#2#2#0#0#9'TCheckBox'#11'cxAllowNull'#4'Left'#2#8#6'Height'#2#17#3
+  +'Top'#3#152#0#5'Width'#2'A'#7'Caption'#6#10'Allow Null'#7'Checked'#9#5'State'
+  +#7#9'cbChecked'#8'TabOrder'#2#5#0#0#7'TBitBtn'#5'bbAdd'#4'Left'#3#230#0#6'He'
+  +'ight'#2#30#3'Top'#3'y'#1#5'Width'#2'K'#7'Caption'#6#3'Add'#5'Color'#4#219
+  +#242#247#0#7'OnClick'#7#10'bbAddClick'#8'TabOrder'#2#6#0#0#9'TSpinEdit'#7'se'
+  +'Order'#4'Left'#2'e'#6'Height'#2#21#3'Top'#2'p'#5'Width'#2'2'#8'MaxValue'#3
+  +#16''''#8'TabOrder'#2#4#5'Value'#2#1#0#0#5'TEdit'#9'edDefault'#4'Left'#2'e'#6
+  +'Height'#2#21#3'Top'#3#186#0#5'Width'#3#204#0#8'TabOrder'#2#7#0#0#6'TLabel'#6
+  +'Label6'#4'Left'#2#8#6'Height'#2#13#3'Top'#3'A'#1#5'Width'#2'N'#7'Caption'#6
+  +#17'Field Description'#11'ParentColor'#8#0#0#5'TEdit'#13'edDescription'#4'Le'
+  +'ft'#2#8#6'Height'#2#21#3'Top'#3'S'#1#5'Width'#3')'#1#8'TabOrder'#2#10#0#0#6
+  +'TLabel'#6'Label7'#4'Left'#3#168#0#6'Height'#2#13#3'Top'#2'Q'#5'Width'#2#25#7
+  +'Caption'#6#5'Scale'#11'ParentColor'#8#0#0#9'TSpinEdit'#7'seScale'#4'Left'#3
+  +#208#0#6'Height'#2#21#4'Hint'#6'0Sets decimal scale for numeric/decimal data'
+  +'types'#3'Top'#2'M'#5'Width'#2'2'#7'Enabled'#8#8'MaxValue'#2#18#14'ParentSho'
+  +'wHint'#8#8'ShowHint'#9#8'TabOrder'#2#3#0#0#9'TComboBox'#9'cbCharset'#4'Left'
+  +#2'e'#6'Height'#2#21#4'Hint'#6'@New field character setIF IT DIFFERS from da'
+  +'tabase character set'#3'Top'#3#224#0#5'Width'#2'|'#7'Enabled'#8#10'ItemHeig'
+  +'ht'#2#13#13'OnEditingDone'#7#20'cbCharsetEditingDone'#8'TabOrder'#2#8#0#0#6
+  +'TLabel'#10'lblCharset'#4'Left'#2#8#6'Height'#2#13#3'Top'#3#228#0#5'Width'#2
+  +'&'#7'Caption'#6#7'Charset'#11'ParentColor'#8#0#0#6'TLabel'#12'lblCollation'
+  +#4'Left'#2#8#6'Height'#2#13#3'Top'#3#12#1#5'Width'#2')'#7'Caption'#6#9'Colla'
+  +'tion'#11'ParentColor'#8#0#0#9'TComboBox'#11'cbCollation'#4'Left'#2'e'#6'Hei'
+  +'ght'#2#21#4'Hint'#6'<Collation of new field IF IT DIFFERS from database col'
+  +'lation'#3'Top'#3#8#1#5'Width'#2'|'#7'Enabled'#8#10'ItemHeight'#2#13#14'Pare'
+  +'ntShowHint'#8#8'ShowHint'#9#8'TabOrder'#2#9#0#0#0
 ]);

+ 6 - 4
neweditfield.pas

@@ -35,8 +35,8 @@ type
     seOrder: TSpinEdit;
     seScale: TSpinEdit;
     procedure bbAddClick(Sender: TObject);
-    procedure cbCharsetChange(Sender: TObject);
-    procedure cbTypeChange(Sender: TObject);
+    procedure cbCharsetEditingDone(Sender: TObject);
+    procedure cbTypeEditingDone(Sender: TObject);
     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     procedure FormCreate(Sender: TObject);
   private
@@ -189,7 +189,7 @@ begin
   Close;
 end;
 
-procedure TfmNewEditField.cbCharsetChange(Sender: TObject);
+procedure TfmNewEditField.cbCharsetEditingDone(Sender: TObject);
 var
   Collations: TStringList;
 begin
@@ -204,7 +204,9 @@ begin
   end;
 end;
 
-procedure TfmNewEditField.cbTypeChange(Sender: TObject);
+
+
+procedure TfmNewEditField.cbTypeEditingDone(Sender: TObject);
 begin
   seSize.Value:= dmSysTables.GetDefaultTypeSize(FDBIndex, cbType.Text);
 

+ 6 - 3
unitfirebirdservices.pas

@@ -31,7 +31,9 @@ type
     procedure SetHostName(const AValue: String);
     procedure SetPassword(const AValue: String);
     procedure SetUserName(const AValue: String);
+    // Raise exception if we cannot attach to service
     procedure RaiseIfNotAttachedService(const S: String);
+    // Run backup or restore depending on BR
     procedure StartBackupRestore(BR: Byte);
     procedure RaiseServiceErr;
 
@@ -41,7 +43,9 @@ type
     function AttachService: Boolean;
     function DetachService: Boolean;
 
+    // Runs a backup on a database
     procedure StartBackup;
+    // Restores a backup file to database
     procedure StartRestore;
     function ServiceQuery(out S: String): Boolean; //Returns True if there is more output.
     // Runs sweep on database
@@ -126,7 +130,7 @@ begin
     isc_action_svc_backup: Msg := 'BACKUP';
     isc_action_svc_restore: Msg := 'RESTORE';
   else
-    Exit;
+    raise EFBServiceError.CreateFmt('Invalid parameter value %d passed to StartBackupRestore',[BR]);
   end;
 
   RaiseIfNotAttachedService(Msg);
@@ -159,7 +163,7 @@ begin
     B := isc_spb_options; // options
     S := S + Char(B);
                           // followed now by for-byte bitmask
-    N := isc_spb_res_replace; // this says replace db file if it exist.
+    N := isc_spb_res_replace; // this says replace db file if it exists.
     B := N mod 256;     // Now, the bytes order in number must be inverted!
     S := S + Char(B);
     N := N div 256;
@@ -178,7 +182,6 @@ begin
 
   if isc_service_start(@FArrIStatus, @FPServHandl, nil, W, @Buff) <> 0 then
     RaiseServiceErr;
-
 end;
 
 procedure TFirebirdServices.RaiseServiceErr;