sqlite component: patch from issue #13209

* Change the sqlite*dataset component editor to allow call the Fields Editor
* Remove workaround to old fpc/lazarus bugs 
patch by Luiz Americo 

git-svn-id: trunk@18764 -
This commit is contained in:
vincents 2009-02-19 20:29:07 +00:00
parent 05fc951f20
commit 3120bb14c2
5 changed files with 110 additions and 118 deletions

View File

@ -1,25 +1,22 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<CONFIG> <CONFIG>
<Package Version="2"> <Package Version="3">
<Name Value="sqlite3laz"/> <Name Value="sqlite3laz"/>
<Author Value="Luiz Américo Pereira Câmara"/> <Author Value="Luiz Américo Pereira Câmara"/>
<CompilerOptions> <CompilerOptions>
<Version Value="5"/> <Version Value="8"/>
<SearchPaths> <SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)"/> <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/$(LCLWidgetType)"/>
</SearchPaths> </SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Other> <Other>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>
<Description Value="TSqlite3Dataset class package <Description Value="TSqlite3Dataset class package
"/> "/>
<License Value="LGPL <License Value="Modified LGPL
"/> "/>
<Version Minor="3"/> <Version Minor="4"/>
<Files Count="2"> <Files Count="2">
<Item1> <Item1>
<Filename Value="registersqlite3.pas"/> <Filename Value="registersqlite3.pas"/>
@ -43,7 +40,7 @@
</Item2> </Item2>
</RequiredPkgs> </RequiredPkgs>
<UsageOptions> <UsageOptions>
<UnitPath Value="$(PkgOutDir)/"/> <UnitPath Value="$(PkgOutDir)\"/>
</UsageOptions> </UsageOptions>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>

View File

@ -1,120 +1,112 @@
object SqliteTableEditorForm: TSqliteTableEditorForm object SqliteTableEditorForm: TSqliteTableEditorForm
Left = 373
Height = 269
Top = 244
Width = 290
ActiveControl = butAdd ActiveControl = butAdd
Caption = 'Sqlite Table Editor' Caption = 'Sqlite Table Editor'
ClientHeight = 269 ClientHeight = 269
ClientWidth = 290 ClientWidth = 290
OnShow = SqliteTableEditorFormShow OnShow = SqliteTableEditorFormShow
PixelsPerInch = 83 LCLVersion = '0.9.27'
HorzScrollBar.Page = 289
VertScrollBar.Page = 268
Left = 373
Height = 269
Top = 244
Width = 290
object Label1: TLabel object Label1: TLabel
Caption = 'Field Name'
Color = clNone
ParentColor = False
Left = 147 Left = 147
Height = 13 Height = 14
Top = 64 Top = 64
Width = 67 Width = 53
Caption = 'Field Name'
ParentColor = False
end end
object Label2: TLabel object Label2: TLabel
Caption = 'Field Type'
Color = clNone
ParentColor = False
Left = 147 Left = 147
Height = 13 Height = 14
Top = 120 Top = 120
Width = 59 Width = 50
Caption = 'Field Type'
ParentColor = False
end end
object lblFilePath: TLabel object lblFilePath: TLabel
Caption = 'lblFilePath'
Color = clNone
ParentColor = False
Left = 8 Left = 8
Height = 13 Height = 14
Top = 4 Top = 4
Width = 61 Width = 49
Caption = 'lblFilePath'
ParentColor = False
end end
object Label3: TLabel object Label3: TLabel
Caption = 'Label3'
Color = clNone
ParentColor = False
Left = 8 Left = 8
Height = 13 Height = 14
Top = 20 Top = 20
Width = 40 Width = 32
Caption = 'Label3'
ParentColor = False
end end
object listFields: TListBox object listFields: TListBox
OnSelectionChange = listFieldsSelectionChange
TabOrder = 6
TopIndex = -1
Left = 8 Left = 8
Height = 192 Height = 192
Top = 64 Top = 64
Width = 124 Width = 124
ItemHeight = 0
OnSelectionChange = listFieldsSelectionChange
TabOrder = 6
end end
object butCreate: TButton object butCreate: TButton
Caption = 'Create Table'
OnClick = butOkClick
TabOrder = 1
TabStop = False
Left = 147 Left = 147
Height = 25 Height = 25
Top = 192 Top = 192
Width = 136 Width = 136
Caption = 'Create Table'
OnClick = butOkClick
TabOrder = 1
TabStop = False
end end
object butClose: TButton object butClose: TButton
Caption = 'Close'
OnClick = butCancelClick
TabOrder = 2
TabStop = False
Left = 147 Left = 147
Height = 25 Height = 25
Top = 232 Top = 232
Width = 136 Width = 136
Caption = 'Close'
OnClick = butCancelClick
TabOrder = 2
TabStop = False
end end
object editFieldName: TEdit object editFieldName: TEdit
OnEditingDone = editFieldNameEditingDone
TabOrder = 4
Left = 147 Left = 147
Height = 23 Height = 23
Top = 80 Top = 80
Width = 136 Width = 136
OnEditingDone = editFieldNameEditingDone
TabOrder = 4
end end
object comboFieldType: TComboBox object comboFieldType: TComboBox
DropDownCount = 12
MaxLength = 0
OnChange = comboFieldTypeChange
Style = csDropDownList
TabOrder = 5
Left = 147 Left = 147
Height = 21 Height = 21
Top = 136 Top = 136
Width = 136 Width = 136
AutoComplete = False
DropDownCount = 12
ItemHeight = 13
ItemWidth = 0
OnChange = comboFieldTypeChange
Style = csDropDownList
TabOrder = 5
end end
object butAdd: TButton object butAdd: TButton
Caption = 'Add'
OnClick = butAddClick
TabOrder = 0
Left = 8 Left = 8
Height = 25 Height = 25
Top = 40 Top = 40
Width = 64 Width = 64
Caption = 'Add'
OnClick = butAddClick
TabOrder = 0
end end
object butDelete: TButton object butDelete: TButton
Caption = 'Delete'
OnClick = butDeleteClick
TabOrder = 3
Left = 72 Left = 72
Height = 25 Height = 25
Top = 40 Top = 40
Width = 60 Width = 60
Caption = 'Delete'
OnClick = butDeleteClick
TabOrder = 3
end end
end end

View File

@ -1,31 +1,32 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TSqliteTableEditorForm','FORMDATA',[ LazarusResources.Add('TSqliteTableEditorForm','FORMDATA',[
'TPF0'#22'TSqliteTableEditorForm'#21'SqliteTableEditorForm'#13'ActiveControl' 'TPF0'#22'TSqliteTableEditorForm'#21'SqliteTableEditorForm'#4'Left'#3'u'#1#6
+#7#6'butAdd'#7'Caption'#6#19'Sqlite Table Editor'#12'ClientHeight'#3#13#1#11 +'Height'#3#13#1#3'Top'#3#244#0#5'Width'#3'"'#1#13'ActiveControl'#7#6'butAdd'
+'ClientWidth'#3'"'#1#6'OnShow'#7#25'SqliteTableEditorFormShow'#13'PixelsPerI' +#7'Caption'#6#19'Sqlite Table Editor'#12'ClientHeight'#3#13#1#11'ClientWidth'
+'nch'#2'S'#18'HorzScrollBar.Page'#3'!'#1#18'VertScrollBar.Page'#3#12#1#4'Lef' +#3'"'#1#6'OnShow'#7#25'SqliteTableEditorFormShow'#10'LCLVersion'#6#6'0.9.27'
+'t'#3'u'#1#6'Height'#3#13#1#3'Top'#3#244#0#5'Width'#3'"'#1#0#6'TLabel'#6'Lab' +#0#6'TLabel'#6'Label1'#4'Left'#3#147#0#6'Height'#2#14#3'Top'#2'@'#5'Width'#2
+'el1'#7'Caption'#6#10'Field Name'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'L' +'5'#7'Caption'#6#10'Field Name'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4
+'eft'#3#147#0#6'Height'#2#13#3'Top'#2'@'#5'Width'#2'C'#0#0#6'TLabel'#6'Label' +'Left'#3#147#0#6'Height'#2#14#3'Top'#2'x'#5'Width'#2'2'#7'Caption'#6#10'Fiel'
+'2'#7'Caption'#6#10'Field Type'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'Lef' +'d Type'#11'ParentColor'#8#0#0#6'TLabel'#11'lblFilePath'#4'Left'#2#8#6'Heigh'
+'t'#3#147#0#6'Height'#2#13#3'Top'#2'x'#5'Width'#2';'#0#0#6'TLabel'#11'lblFil' +'t'#2#14#3'Top'#2#4#5'Width'#2'1'#7'Caption'#6#11'lblFilePath'#11'ParentColo'
+'ePath'#7'Caption'#6#11'lblFilePath'#5'Color'#7#6'clNone'#11'ParentColor'#8#4 +'r'#8#0#0#6'TLabel'#6'Label3'#4'Left'#2#8#6'Height'#2#14#3'Top'#2#20#5'Width'
+'Left'#2#8#6'Height'#2#13#3'Top'#2#4#5'Width'#2'='#0#0#6'TLabel'#6'Label3'#7 +#2' '#7'Caption'#6#6'Label3'#11'ParentColor'#8#0#0#8'TListBox'#10'listFields'
+'Caption'#6#6'Label3'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'Left'#2#8#6'H' +#4'Left'#2#8#6'Height'#3#192#0#3'Top'#2'@'#5'Width'#2'|'#10'ItemHeight'#2#0
+'eight'#2#13#3'Top'#2#20#5'Width'#2'('#0#0#8'TListBox'#10'listFields'#17'OnS' +#17'OnSelectionChange'#7#25'listFieldsSelectionChange'#8'TabOrder'#2#6#0#0#7
+'electionChange'#7#25'listFieldsSelectionChange'#8'TabOrder'#2#6#8'TopIndex' +'TButton'#9'butCreate'#4'Left'#3#147#0#6'Height'#2#25#3'Top'#3#192#0#5'Width'
+#2#255#4'Left'#2#8#6'Height'#3#192#0#3'Top'#2'@'#5'Width'#2'|'#0#0#7'TButton' +#3#136#0#7'Caption'#6#12'Create Table'#7'OnClick'#7#10'butOkClick'#8'TabOrde'
+#9'butCreate'#7'Caption'#6#12'Create Table'#7'OnClick'#7#10'butOkClick'#8'Ta' +'r'#2#1#7'TabStop'#8#0#0#7'TButton'#8'butClose'#4'Left'#3#147#0#6'Height'#2
+'bOrder'#2#1#7'TabStop'#8#4'Left'#3#147#0#6'Height'#2#25#3'Top'#3#192#0#5'Wi' +#25#3'Top'#3#232#0#5'Width'#3#136#0#7'Caption'#6#5'Close'#7'OnClick'#7#14'bu'
+'dth'#3#136#0#0#0#7'TButton'#8'butClose'#7'Caption'#6#5'Close'#7'OnClick'#7 +'tCancelClick'#8'TabOrder'#2#2#7'TabStop'#8#0#0#5'TEdit'#13'editFieldName'#4
+#14'butCancelClick'#8'TabOrder'#2#2#7'TabStop'#8#4'Left'#3#147#0#6'Height'#2 +'Left'#3#147#0#6'Height'#2#23#3'Top'#2'P'#5'Width'#3#136#0#13'OnEditingDone'
+#25#3'Top'#3#232#0#5'Width'#3#136#0#0#0#5'TEdit'#13'editFieldName'#13'OnEdit' +#7#24'editFieldNameEditingDone'#8'TabOrder'#2#4#0#0#9'TComboBox'#14'comboFie'
+'ingDone'#7#24'editFieldNameEditingDone'#8'TabOrder'#2#4#4'Left'#3#147#0#6'H' +'ldType'#4'Left'#3#147#0#6'Height'#2#21#3'Top'#3#136#0#5'Width'#3#136#0#12'A'
+'eight'#2#23#3'Top'#2'P'#5'Width'#3#136#0#0#0#9'TComboBox'#14'comboFieldType' +'utoComplete'#8#13'DropDownCount'#2#12#10'ItemHeight'#2#13#9'ItemWidth'#2#0#8
+#13'DropDownCount'#2#12#9'MaxLength'#2#0#8'OnChange'#7#20'comboFieldTypeChan' +'OnChange'#7#20'comboFieldTypeChange'#5'Style'#7#14'csDropDownList'#8'TabOrd'
+'ge'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#5#4'Left'#3#147#0#6'Height' +'er'#2#5#0#0#7'TButton'#6'butAdd'#4'Left'#2#8#6'Height'#2#25#3'Top'#2'('#5'W'
+#2#21#3'Top'#3#136#0#5'Width'#3#136#0#0#0#7'TButton'#6'butAdd'#7'Caption'#6#3 +'idth'#2'@'#7'Caption'#6#3'Add'#7'OnClick'#7#11'butAddClick'#8'TabOrder'#2#0
+'Add'#7'OnClick'#7#11'butAddClick'#8'TabOrder'#2#0#4'Left'#2#8#6'Height'#2#25 +#0#0#7'TButton'#9'butDelete'#4'Left'#2'H'#6'Height'#2#25#3'Top'#2'('#5'Width'
+#3'Top'#2'('#5'Width'#2'@'#0#0#7'TButton'#9'butDelete'#7'Caption'#6#6'Delete' +#2'<'#7'Caption'#6#6'Delete'#7'OnClick'#7#14'butDeleteClick'#8'TabOrder'#2#3
+#7'OnClick'#7#14'butDeleteClick'#8'TabOrder'#2#3#4'Left'#2'H'#6'Height'#2#25 +#0#0#0
+#3'Top'#2'('#5'Width'#2'<'#0#0#0
]); ]);

View File

@ -18,13 +18,16 @@ interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs, StdCtrls, Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs, StdCtrls,
Buttons, customsqliteds, ComponentEditors, LazarusPackageIntf, LazIdeIntf; Buttons, customsqliteds, ComponentEditors, LazarusPackageIntf, LazIdeIntf,
fieldseditor;
type type
{TSqliteEditor} {TSqliteEditor}
TSqliteEditor = class(TComponentEditor) TSqliteEditor = class(TFieldsComponentEditor)
private
FVerbOffset: Integer;
public public
procedure ExecuteVerb(Index: Integer); override; procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override; function GetVerb(Index: Integer): string; override;
@ -69,9 +72,6 @@ implementation
uses uses
db; db;
var
IsAddingField:Boolean;//hack to avoid LCL bug 1428
function StringListHasDuplicates(const List:TStrings):boolean; function StringListHasDuplicates(const List:TStrings):boolean;
var var
i,j:Integer; i,j:Integer;
@ -90,33 +90,35 @@ end;
procedure TSqliteEditor.ExecuteVerb(Index: Integer); procedure TSqliteEditor.ExecuteVerb(Index: Integer);
begin begin
case Index of case Index - FVerbOffset of
0: Edit; 0: Edit;
else
inherited ExecuteVerb(Index);
end; end;
end; end;
function TSqliteEditor.GetVerb(Index: Integer): string; function TSqliteEditor.GetVerb(Index: Integer): string;
begin begin
case Index of case Index - FVerbOffset of
0: 0:
begin begin
if not TCustomSqliteDataset(GetComponent).TableExists then Result := 'Create/Edit Table'
Result:='Create Table'
else
Result:='Edit Table';
end; end;
else
Result := inherited GetVerb(Index);
end; end;
end; end;
function TSqliteEditor.GetVerbCount: Integer; function TSqliteEditor.GetVerbCount: Integer;
begin begin
Result:=1; FVerbOffset := inherited GetVerbCount;
Result := FVerbOffset + 1;
end; end;
procedure TSqliteEditor.Edit; procedure TSqliteEditor.Edit;
var var
ADataSet:TCustomSqliteDataSet; ADataSet:TCustomSqliteDataSet;
OldDir:String; OldDir, ProjectDir:String;
begin begin
ADataSet:=TCustomSqliteDataSet(GetComponent); ADataSet:=TCustomSqliteDataSet(GetComponent);
if ADataSet.Filename = '' then if ADataSet.Filename = '' then
@ -136,8 +138,9 @@ begin
// In case Filename is a relative one, change dir to project dir // In case Filename is a relative one, change dir to project dir
// so the datafile will be created in the right place // so the datafile will be created in the right place
OldDir := GetCurrentDirUTF8; OldDir := GetCurrentDirUTF8;
if ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName) <> '' then ProjectDir := ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName);
SetCurrentDirUTF8(ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName)); if ProjectDir <> '' then
SetCurrentDirUTF8(ProjectDir);
Dataset := ADataset; Dataset := ADataset;
ShowModal; ShowModal;
finally finally
@ -154,9 +157,7 @@ begin
//In the case there's no items //In the case there's no items
editFieldName.Enabled:=True; editFieldName.Enabled:=True;
comboFieldType.Enabled:=True; comboFieldType.Enabled:=True;
IsAddingField:=True; //to be removed
listFields.Items.AddObject('AFieldName',TObject(ftString)); listFields.Items.AddObject('AFieldName',TObject(ftString));
IsAddingField:=False;
listFields.ItemIndex:=listFields.Items.Count-1; listFields.ItemIndex:=listFields.Items.Count-1;
editFieldName.Text:='AFieldName'; editFieldName.Text:='AFieldName';
editFieldName.SetFocus; editFieldName.SetFocus;
@ -208,7 +209,6 @@ procedure TSqliteTableEditorForm.SetComboValue(AObject: TObject);
var var
AIndex:Integer; AIndex:Integer;
begin begin
//warning: using inline in this function causes a crash with fpc 2.0.0
AIndex:=comboFieldType.Items.IndexOfObject(AObject); AIndex:=comboFieldType.Items.IndexOfObject(AObject);
if AIndex <> -1 then if AIndex <> -1 then
@ -317,7 +317,7 @@ end;
procedure TSqliteTableEditorForm.listFieldsSelectionChange(Sender: TObject; procedure TSqliteTableEditorForm.listFieldsSelectionChange(Sender: TObject;
User: boolean); User: boolean);
begin begin
if (listFields.ItemIndex <> -1) and not IsAddingField then //remove when LCL is fixed if (listFields.ItemIndex <> -1) then
begin begin
editFieldName.Text:=listFields.Items[listFields.ItemIndex]; editFieldName.Text:=listFields.Items[listFields.ItemIndex];
SetComboValue(listFields.Items.Objects[listFields.ItemIndex]); SetComboValue(listFields.Items.Objects[listFields.ItemIndex]);

View File

@ -12,9 +12,11 @@
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>
<Description Value="TSqliteDataset class package"/> <Description Value="TSqliteDataset class package
<License Value="LGPL"/> "/>
<Version Minor="3"/> <License Value="Modified LGPL
"/>
<Version Minor="4"/>
<Files Count="3"> <Files Count="3">
<Item1> <Item1>
<Filename Value="registersqlite.pas"/> <Filename Value="registersqlite.pas"/>
@ -43,7 +45,7 @@
</Item2> </Item2>
</RequiredPkgs> </RequiredPkgs>
<UsageOptions> <UsageOptions>
<UnitPath Value="$(PkgOutDir)/"/> <UnitPath Value="$(PkgOutDir)\"/>
</UsageOptions> </UsageOptions>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>