Jelajahi Sumber

Do not preselect character set combobox for new/edit fields

Reinier Olislagers 11 tahun lalu
induk
melakukan
167cbb03a6
4 mengubah file dengan 15 tambahan dan 12 penghapusan
  1. 0 1
      neweditfield.lfm
  2. 8 8
      neweditfield.lrs
  3. 5 2
      neweditfield.pas
  4. 2 1
      newtable.pas

+ 0 - 1
neweditfield.lfm

@@ -168,7 +168,6 @@ object fmNewEditField: TfmNewEditField
     ItemHeight = 13
     OnChange = cbCharsetChange
     TabOrder = 8
-    Text = 'NONE'
   end
   object lblCharset: TLabel
     Left = 8

+ 8 - 8
neweditfield.lrs

@@ -42,12 +42,12 @@ LazarusResources.Add('TfmNewEditField','FORMDATA',[
   +'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#4'Text'#6#4'NONE'#0#0#6'TLab'
-  +'el'#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'Le'
-  +'ft'#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'<Collation of new field IF IT DIFFERS from database collation'
-  +#3'Top'#3#8#1#5'Width'#2'|'#7'Enabled'#8#10'ItemHeight'#2#13#14'ParentShowHi'
-  +'nt'#8#8'ShowHint'#9#8'TabOrder'#2#9#0#0#0
+  +'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
 ]);

+ 5 - 2
neweditfield.pas

@@ -192,7 +192,8 @@ procedure TfmNewEditField.cbCharsetChange(Sender: TObject);
 var
   Collations: TStringList;
 begin
-  // Available collations depend on the chosen character set, so update that
+  // Available collations depend on the chosen character set,
+  // so update that whenever user changes character set
   Collations:= TStringList.Create;
   try
     GetCollations(cbCharSet.Text,Collations);
@@ -244,7 +245,9 @@ begin
   // Load available character sets
   // todo: (low priority) character sets should be retrieved from current database server
   CbCharSet.Items.AddStrings(FBCharacterSets);
-  CbCharSet.ItemIndex:=DefaultFBCharacterSet;
+  // Do not set a default value, but leave it empty, because specifying a charset
+  // is not mandatory - it should only be done if the charset differs from the
+  // db charset
 end;
 
 procedure TfmNewEditField.Init(dbIndex: Integer; TableName: string;

+ 2 - 1
newtable.pas

@@ -95,7 +95,8 @@ begin
       // Default value
       if Trim(StringGrid1.Cells[5, i]) <> '' then
       begin
-        if (Pos('CHAR', FieldType) > 0) and (Pos('''', StringGrid1.Cells[5, i]) = 0) then
+        if ((Pos('CHAR', FieldType) > 0) or (FieldType='CSTRING')) and
+          (Pos('''', StringGrid1.Cells[5, i]) = 0) then
           FieldLine:= FieldLine + ' default ' + QuotedStr(StringGrid1.Cells[5, i])
         else
           FieldLine:= FieldLine + ' default ' + StringGrid1.Cells[5, i];