Recent

Author Topic: TDBGrid Enhansement (Add all columns from the dataset)  (Read 17007 times)

zgabrovski

  • New Member
  • *
  • Posts: 33
TDBGrid Enhansement (Add all columns from the dataset)
« on: October 17, 2013, 11:30:10 am »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #1 on: October 17, 2013, 11:48:01 am »
Great - thanks for helping improve Lazarus!

I 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.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #2 on: October 17, 2013, 12:37:21 pm »
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;     
     
« Last Edit: October 17, 2013, 02:00:17 pm by zgabrovski »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #3 on: October 17, 2013, 01:16:06 pm »
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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #4 on: October 17, 2013, 02:18:28 pm »
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

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #5 on: October 18, 2013, 01:18:59 pm »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #7 on: October 18, 2013, 01:44:17 pm »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #8 on: October 18, 2013, 01:46:48 pm »
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.
« Last Edit: October 18, 2013, 01:48:51 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #9 on: October 18, 2013, 01:58:44 pm »
OK,
Can you please help me how to do this (I am not so familiar with svn )?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #10 on: October 18, 2013, 02:07:44 pm »
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)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #11 on: October 18, 2013, 02:14:06 pm »
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...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #12 on: October 18, 2013, 10:21:09 pm »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #13 on: October 19, 2013, 10:43:33 am »
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.
« Last Edit: October 19, 2013, 03:57:46 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

zgabrovski

  • New Member
  • *
  • Posts: 33
Re: TDBGrid Enhansement (Add all columns from the dataset)
« Reply #14 on: October 19, 2013, 08:10:00 pm »
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?

 

TinyPortal © 2005-2018