TDBGrid Enhansement (Add all columns from the dataset) lazarus / 31-LCL ---------------------------------------------------------------------- zgabrovski · 2013-10-17 09:30 Dear all, here is the small enhancement I did: When I start to port a Delphi 5 project to lazarus, I found, that TColumns editor uses standart TCollection editor and there is no option to add all the columns from the dataset. Here is my modification in the unit CollectionPropEditForm: I check if the collection type is TDBGridColumn, and if it is - display the button "Add fileds" which clear columns collection and add it from the dataset fields property. May be the right way is to register a new propery editor for the TDBGridColumns property? I don't know where to propose this enhancement, I think this will be better for all developers. ---------------------------------------------------------------------- BigChimp · 2013-10-17 09:48 Great - thanks for helping improve Lazarus! Quote from: zgabrovski on October 17, 2013, 11:30:10 amI don't know where to propose this enhancement, I think this will be better for all developers. You can discuss plans for improvements here, as you are doing. Once you are finished with improvements (or get stuck but do think your improvements are useful), you can post them to the bugtracker/issue tracker (see link top left here) as a patch against Lazarus trunk. See the articles on how to submit a patch on the wiki (which I can't reach right now). Thanks a lot. ---------------------------------------------------------------------- zgabrovski · 2013-10-17 10:37 OK, let's start a discussion - to keep an enhancement into collectionpropeditform.pas, like I did, or to create a new property editor, specially for TDBGridColumns collection? In the current way I add a reference to DBGrids into collectionpropeditform.pas, because of access to the types I need. Also, add a new Acttion "actAddFields" in the action list and new separator and button into toolbar. The new action and button are visible and enabled only if the collection type is TDBGridColumns. When the user select this button, here is the method implementation: Code: [Select]procedure TCollectionPropertyEditorForm.actAddFieldsExecute(Sender: TObject); var It : TCollectionItem;   flChanged : Boolean;   flEmpty : Boolean;   i : Integer; begin   //     if Collection = nil then Exit;     if not ( Collection is TDBGridColumns ) then Exit;     flChanged := False;     flEmpty := False;   //Collection.Add;   //   //FillCollectionListBox;   //if CollectionListBox.Items.Count > 0 then   //  CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1;   //SelectInObjectInspector(True, False);   //UpdateButtons;   //UpdateCaption;   //Modified;   if Collection.Count > 0 then     It := Collection.Items[ 0 ]   else begin     It := Collection.Add;     flEmpty:=True;   end;   if flEmpty or ( MessageDlg( fesFeTitle, oisConfirmDelete+oisAddFields+'?',       mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then begin       try         if (It is TColumn) and ( Assigned( TDBGrid( TColumn( It ).Grid).DataSource ) ) and           Assigned ( TDBGrid( TColumn( It ).Grid).DataSource.DataSet ) then begin           flChanged:=True;           BeginFormUpdate;           Collection.Clear;           It := Collection.Add; //          TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Open;           if TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count > 0 then begin             for i := 0 to TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count - 1 do begin               if i > 0 then begin                 It := Collection.Add;               end;               TColumn( It ).Field:=TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields[ i ];               end;             end;           end;       finally         if flChanged then begin           RefreshPropertyValues;           UpdateButtons;           UpdateCaption;           Modified;           EndFormUpdate;           end         else           if flEmpty then begin             Collection.Clear;             RefreshPropertyValues;             UpdateButtons;             UpdateCaption;             Modified;             EndFormUpdate;             end;           end;       end; end; ---------------------------------------------------------------------- taazz · 2013-10-17 11:16 1) enclose code inside the code tags ee the # symbol in the editor. 2) since this is TDBGridColumns specific editor it should   a) inherit from the TcollectionEditor instead of copying it and changing what ever.   b) Register it self only for TDBGridColumns properties. That should be easy enough. ---------------------------------------------------------------------- zgabrovski · 2013-10-17 12:18 OK, finally: 1.I will create a new form for TDBGridColumns edinting, called TDBGrigColumnsPropertyEditorForm into new unit DBGrigColumnsPropEditForm. 2. Into DBPropEdits module I must replace Code: [Select]procedure TDBGridComponentEditor.ExecuteVerb(Index: Integer); var   Hook: TPropertyEditorHook;   DBGrid: TDBGrid; begin   DBGrid := GetComponent as TDBGrid;   GetHook(Hook);   EditCollection(DBGrid, DBGrid.Columns, 'Columns');   if Assigned(Hook) then Hook.Modified(Self); end; EditCollection(DBGrid, DBGrid.Columns, 'Columns'); With a new method, (EditColumns(DBGrid); for example ), which I will implement into new unit DBGrigColumnsPropEditForm. 3. Finally, I must register a property editor  for TDBGridColumns,i.e. TDBGridColumnsPropertyEditor = class (TCollectionPropertyEditor) With a new "Edit" method implementation, that will call a new form TDBGrigColumnsPropertyEditorForm. Am I on the right way? Sorry for the questions, but last time I wrote a Delphi component was 10 years ago, I forgot some thinks ---------------------------------------------------------------------- zgabrovski · 2013-10-18 11:18 I am ready. New property editor form and changes in dbpropedits.pas are in the attached files. Also, I add a new button - "Delete all fields". I am not so familiary with a bugtracker, can somebody help me how to add changes? Regards, Zdravko. ---------------------------------------------------------------------- BigChimp · 2013-10-18 11:21 http://wiki.lazarus.freepascal.org/Creating_A_Patch http://wiki.lazarus.freepascal.org/How_do_I_create_a_bug_report http://wiki.lazarus.freepascal.org/Tips_on_writing_bug_reports ---------------------------------------------------------------------- zgabrovski · 2013-10-18 11:44 At the moment I am usign Code Typhon, is there a difference from Lazarus? I can download and install Lazarus, if it is necessaray. ---------------------------------------------------------------------- BigChimp · 2013-10-18 11:46 There are differences, yes. AFAIU, CodeTyphon is a tweaked version of a development snapshot of Lazarus. Please download the trunk/development version of Lazarus (using subversion manually or fpcup) and write a patch for it. Edit: I suppose a recent Lazarus snapshot would also be okay, but that would be less easy to keep up to date... Thanks. ---------------------------------------------------------------------- zgabrovski · 2013-10-18 11:58 OK, Can you please help me how to do this (I am not so familiar with svn )? ---------------------------------------------------------------------- BigChimp · 2013-10-18 12:07 You may notice a trend here, but here goes, another wiki page: http://wiki.lazarus.freepascal.org/Installing_Lazarus#Installing_from_ source_2 (and yes, this page is horrrible. I've given up trying to improve it). alternatively, use fpcup https://bitbucket.org/reiniero/fpcup/downloads suggest the x86/32 bit version: fpcup.exe create a directory c:\development; make sure you have write access to it, then run fpcup: fpcup --lazurl=trunk (and go and drink coffee) ---------------------------------------------------------------------- BigChimp · 2013-10-18 12:14 Of course, I'm a bit biased and prefer to use fpcup If you hit any problems, please feel free to post, preferably in a new thread... ---------------------------------------------------------------------- zgabrovski · 2013-10-18 20:21 Sorry, but when I try to do, I received the following: Code: [Select]Info: TFPCInstaller: building module fpc... Info: Running Make all (FPC crosscompiler: x86_64-win64) ERROR: FPC: Running fpc crossinstall make all failed with an error code. ERROR: Error running BuildModuleCustom for module fpc Info: Error running fpcup. Technical details: error executing sequence crosswin3 2-64; line: 5, param: fpc Info: Error running fpcup. Technical details: error executing sequence DefaultWi n32; line: 9, param: crosswin32-64 FPCUp failed. Please check log for details. Possible troubleshooting steps: - run again with --verbose and check for make, lazbuild errors etc. - make sure there's a valid SVN executable in your path. - if compiling Lazarus, make sure your lhelp is closed. - try removing all intermediate files by running fpcup with the --clean option   and/or manually deleting all *.ppu/*.a/*.o followed by svn up - if that does not work: use the --uninstall option to remove all files   including your FPC and Lazarus directories - remove the bootstrap compiler. fpcup will download it if required. Info: 18.10.2013 г. 21:59:06: fpcup finished. Where is the the problem? ---------------------------------------------------------------------- BigChimp · 2013-10-19 08:43 It's erroring out when building an FPC x86=>x64 crosscompiler. Edit: turns out FPC 2.6.2 has problems building a cross compiler (which are probably solved in fpc 2.6.3 and certainly in fpc trunk, but that's not the point). I've uploaded a new version of fpcup that ignores these cross compiling errors, so it should work correctly. Sorry for the inconvenience, and pleae report any further problems. Thanks. ---------------------------------------------------------------------- zgabrovski · 2013-10-19 18:10 Using your previous instruction ( fpcup --lazurl=trunk --skip=crosswin32-64 ) I built a Development lazarus snapshot. What should be next step? To apply my changes in DBPropedits and to put new DBGridColumntsEditorform into this development edition? I check how to create a patch, it is written to use command line svn utility, can you please recommend me from where to download this command line utility? ---------------------------------------------------------------------- BigChimp · 2013-10-19 19:37 quick note: 1. svn client fpcup has already downloaded an svn client for you It should be in a subdirectory of c:\development\fpcbootstrap\; it's called svn.exe If you want a graphical SVN client which is very nice, you can download and install TortoiseSVN. 2. changes Yes, you go ahead and change everything the way you want it, recompile Lazarus, check everything looks ok. Then you can go to c:\development\lazarus and run svn diff to list the differences/show the patch; do svn diff > thepatch.diff to save the patch etc. ---------------------------------------------------------------------- zgabrovski · 2013-10-19 20:37 OK, I an ready with the patch file. But I check, it contains only changes into DBPropedits.pas. The new .pas and .lfm file for property editor form is not included in the patch.diff file. Must I attach those two other files in the bug tracker? ---------------------------------------------------------------------- BigChimp · 2013-10-20 08:07 Quote from: zgabrovski on October 19, 2013, 10:37:35 pmOK, I an ready with the patch file. Great work! Quote from: zgabrovski on October 19, 2013, 10:37:35 pmBut I check, it contains only changes into DBPropedits.pas. The new .pas and .lfm file for property editor form is not included in the patch.diff file. Yes, that's normal with patch files. Quote from: zgabrovski on October 19, 2013, 10:37:35 pmMust I attach those two other files in the bug tracker? Yes, please attach them along with the patch (or zip them up first if they're a bit bigger). ---------------------------------------------------------------------- zgabrovski · 2013-10-20 08:46 I hope that I upload the patch successfully. Can you please check? http://bugs.freepascal.org/view.php?id=25219 ---------------------------------------------------------------------- BigChimp · 2013-10-20 09:52 Great, thanks. Some remarks: - it's often useful to indicate in which directory the new files should go (i.e. $(lazarusdir)\components\ideintf) - Typo: you spelled the filenames DBGrigColumns... instead of DBGfid. Also, the rest of the files there use lowercase, so probably best to use the same convention - your indentation in the patch (TDBGridColumnsPropertyEditor = class (TCollectionPropertyEditor)) does not match the rest of the code - typo in function name, some vertical linespace. Minor stuff really.... but the kind of stuff I can check easily No idea about the actual content though, so no comments there I took the liberty of creating a new patch and renaming the files. If ok, could you upload them to the issue tracker? Thanks a lot ---------------------------------------------------------------------- zgabrovski · 2013-10-20 14:50 It is OK, n.p. I upload new file, but how to remove old one? ---------------------------------------------------------------------- BigChimp · 2013-10-20 14:54 You can't remove the old one if you have bug reporter privileges. I'll remove the old one for you... I also assigned it to somebody who I think is the right guy for Laz DB controls patches. Thanks a lot for your hard work! ---------------------------------------------------------------------- zgabrovski · 2013-10-20 15:25 It was a pleasure for me. If I find other thinks, that I can improve, I will do. ---------------------------------------------------------------------- BigChimp · 2013-10-20 15:37 Please do keep an eye on the bugtracker issue though, you might get some feedback there...