View Issue Details

IDProjectCategoryView StatusLast Update
0023045LazarusIDEpublic2016-01-15 23:44
Reportersilvioprog Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.1 (SVN) 
Summary0023045: registersqldb: Auto declare unit in uses
DescriptionPlease apply the patch in attached. It declares the unit of connector when you choose the the property "ConnectorType". Please see a small demonstration here:

http://imagebin.org/230685

Sorry for my englysh, thank you.
Tagspatch
Fixed in Revisionr40927
LazTarget-
Widgetset
Attached Files

Relationships

related to 0023928 new Removing unneeded controls and lazarus automatically removes those required units for that or those controls 

Activities

2012-10-03 01:11

 

registersqldb.pas.patch (1,495 bytes)   
Index: registersqldb.pas
===================================================================
--- registersqldb.pas	(revision 38953)
+++ registersqldb.pas	(working copy)
@@ -111,7 +111,9 @@
   lazideintf,
   srceditorintf,
   ProjectIntf,
-  idemsgintf;
+  idemsgintf,
+  CodeCache,
+  CodeToolManager;
 
 Type
   { TSQLStringsPropertyEditor }
@@ -149,6 +151,7 @@
   public
     function GetAttributes: TPropertyAttributes; override;
     procedure GetValues(Proc: TGetStrProc); override;
+    procedure SetValue(const NewValue: ansistring); override;
   end;
 
 {$IFDEF HASLIBLOADER}
@@ -273,6 +276,31 @@
   end;
 end;
 
+procedure TSQLDBConnectorTypePropertyEditor.SetValue(const NewValue: ansistring);
+var
+  Comp: TPersistent;
+  Code: TCodeBuffer;
+  ConnDef: TConnectionDef;
+  SrcEdit: TSourceEditorInterface;
+begin
+  SrcEdit := SourceEditorManagerIntf.ActiveEditor;
+  if Assigned(SrcEdit) then
+    Code := TCodeBuffer(SrcEdit.CodeToolsBuffer);
+  if Code = nil then
+    Exit;
+  Comp := GetComponent(0);
+  if Comp is TSQLConnector then
+  begin
+    ConnDef := GetConnectionDef(TSQLConnector(Comp).ConnectorType);
+    if Assigned(ConnDef) then
+      CodeToolBoss.RemoveUnitFromAllUsesSections(Code, ConnDef.UnitName);
+    ConnDef := GetConnectionDef(NewValue);
+    if Assigned(ConnDef) then
+      CodeToolBoss.AddUnitToMainUsesSection(Code, ConnDef.UnitName, '');
+  end;
+  inherited;
+end;
+
 {$IFDEF HASLIBLOADER}
 { TSQLDBLibraryLoaderLibraryNamePropertyEditor }
 
registersqldb.pas.patch (1,495 bytes)   

Mattias Gaertner

2012-10-03 08:40

manager   ~0062842

You forgot

  // commit editor changes to codetools
  if not LazarusIDE.BeginCodeTools then exit;

silvioprog

2012-10-03 23:14

reporter   ~0062869

Perfect Mattias! :)

New patch in attached. (registersqldb-NEW-20121003-1813.pas.patch)

2012-10-03 23:15

 

registersqldb-NEW-20121003-1813.pas.patch (1,547 bytes)   
Index: registersqldb.pas
===================================================================
--- registersqldb.pas	(revision 38962)
+++ registersqldb.pas	(working copy)
@@ -111,7 +111,9 @@
   lazideintf,
   srceditorintf,
   ProjectIntf,
-  idemsgintf;
+  idemsgintf,
+  CodeCache,
+  CodeToolManager;
 
 Type
   { TSQLStringsPropertyEditor }
@@ -149,6 +151,7 @@
   public
     function GetAttributes: TPropertyAttributes; override;
     procedure GetValues(Proc: TGetStrProc); override;
+    procedure SetValue(const NewValue: ansistring); override;
   end;
 
 {$IFDEF HASLIBLOADER}
@@ -273,6 +276,33 @@
   end;
 end;
 
+procedure TSQLDBConnectorTypePropertyEditor.SetValue(const NewValue: ansistring);
+var
+  Comp: TPersistent;
+  Code: TCodeBuffer;
+  ConnDef: TConnectionDef;
+  SrcEdit: TSourceEditorInterface;
+begin
+  if not LazarusIDE.BeginCodeTools then
+    Exit;
+  SrcEdit := SourceEditorManagerIntf.ActiveEditor;
+  if Assigned(SrcEdit) then
+    Code := TCodeBuffer(SrcEdit.CodeToolsBuffer);
+  if Code = nil then
+    Exit;
+  Comp := GetComponent(0);
+  if Comp is TSQLConnector then
+  begin
+    ConnDef := GetConnectionDef(TSQLConnector(Comp).ConnectorType);
+    if Assigned(ConnDef) then
+      CodeToolBoss.RemoveUnitFromAllUsesSections(Code, ConnDef.UnitName);
+    ConnDef := GetConnectionDef(NewValue);
+    if Assigned(ConnDef) then
+      CodeToolBoss.AddUnitToMainUsesSection(Code, ConnDef.UnitName, '');
+  end;
+  inherited;
+end;
+
 {$IFDEF HASLIBLOADER}
 { TSQLDBLibraryLoaderLibraryNamePropertyEditor }
 

Ludo Brands

2012-10-08 09:48

developer   ~0062993

When changing ConnectorType from x to y you remove the unit for x before adding the unit for y. This is IMHO a bad idea. What about applications that are written for multiple db back-ends and that use TSQLConnector as a common interface? Changing the default ConnectorType in the OI would then delete a unit from the uses clause instead of just changing the default.
When you drop for example a TSQLite3Connection on a form, sqlite3conn will be added to the uses clause. Remove the TSQLite3Connection from the form, sqlite3conn is not needed any more but it is still in the uses section.

silvioprog

2012-10-12 02:59

reporter   ~0063090

Hm... so, you think it would be better keep the old unit declared?

Ludo Brands

2012-10-12 07:48

developer   ~0063092

Yes. Better one unit too many than a missing unit. A missing db connection unit will go unnoticed until run time and only when you need that particular db connection. Very vicious.
Now, I don't know enough of the IDE internals to know what happens if for example you use the keyboard to scroll through the list of connector types in the OI. Are all the connector types added that you scrolled through or only the one highlighted when you exit the OI scroll box? The same question for when you click on the wrong connector type but, before exiting the control, correct immediately. Depending on the answer you have perhaps to use another event to trigger the update of the connector type and the inclusion of the unit.

silvioprog

2012-11-09 00:14

reporter   ~0063758

If you selects an item wrong by accident, you have to remove the unit manually.

I can create a new patch that doesn't remove the unit automatically.

Juha Manninen

2013-04-29 10:14

developer   ~0067249

Last edited: 2013-04-29 10:16

View 2 revisions

I understood the automatic removal was not desired.
I removed these 3 lines from the patch :

+ ConnDef := GetConnectionDef(TSQLConnector(Comp).ConnectorType);
+ if Assigned(ConnDef) then
+ CodeToolBoss.RemoveUnitFromAllUsesSections(Code, ConnDef.UnitName);


... and applied it in r40927.
Please test. I will resolve this issue after it gets tested.

I added a related issue about automatic removal of units.
It sounds like a good idea. I don't know how many problems it creates though.

Mattias Gaertner

2013-04-29 10:38

manager   ~0067250

About keyboard navigation in OI:
yes, the OI combobox set the value too often. This depends on widgetsets.

silvioprog

2013-06-11 16:41

reporter   ~0068223

Now I saw it implemented in Lazarus. Please close this issue. Thank you very much! :)

Juha Manninen

2013-06-11 18:19

developer   ~0068225

Resolving...

Issue History

Date Modified Username Field Change
2012-10-03 01:11 silvioprog New Issue
2012-10-03 01:11 silvioprog File Added: registersqldb.pas.patch
2012-10-03 01:12 silvioprog Tag Attached: patch
2012-10-03 08:40 Mattias Gaertner Note Added: 0062842
2012-10-03 23:14 silvioprog Note Added: 0062869
2012-10-03 23:15 silvioprog File Added: registersqldb-NEW-20121003-1813.pas.patch
2012-10-08 09:48 Ludo Brands Note Added: 0062993
2012-10-12 02:59 silvioprog Note Added: 0063090
2012-10-12 07:48 Ludo Brands Note Added: 0063092
2012-11-09 00:14 silvioprog Note Added: 0063758
2013-04-29 09:40 Juha Manninen Assigned To => Juha Manninen
2013-04-29 09:40 Juha Manninen Status new => assigned
2013-04-29 09:42 Juha Manninen Relationship added related to 0023928
2013-04-29 10:14 Juha Manninen LazTarget => -
2013-04-29 10:14 Juha Manninen Note Added: 0067249
2013-04-29 10:14 Juha Manninen Status assigned => feedback
2013-04-29 10:16 Juha Manninen Note Edited: 0067249 View Revisions
2013-04-29 10:38 Mattias Gaertner Note Added: 0067250
2013-06-11 16:41 silvioprog Note Added: 0068223
2013-06-11 16:41 silvioprog Status feedback => assigned
2013-06-11 18:19 Juha Manninen Fixed in Revision => r40927
2013-06-11 18:19 Juha Manninen Note Added: 0068225
2013-06-11 18:19 Juha Manninen Status assigned => resolved
2013-06-11 18:19 Juha Manninen Resolution open => fixed
2016-01-15 23:44 silvioprog Status resolved => closed