Recent

Author Topic: RX Library RXDBGrid and TDateTime  (Read 5430 times)

andreaboc

  • Newbie
  • Posts: 4
RX Library RXDBGrid and TDateTime
« on: May 05, 2021, 09:28:28 am »
Hi,
I'm using RXDBGrid with ZEOSLib for a project to explore PostgreSQL database.
My Application is a very simple PostgreSQL query bulder, a lightweight alternative of PgAdmin.
In this application you can write SQL queryes and view the result in the RXDBGrid placed bottom of the SynEdit Editor, and if you want you can edit data.
The problem is for timestamp columns (TDateTime): RxDBGrid try to handle this type with Date Editor
Code: Pascal  [Select][+][-]
  1. FRxDbGridLookupComboEditor
in accord with the function:
Code: Pascal  [Select][+][-]
  1. function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
but data contains both date and time and the control show only date withoout the possibility to edit time.
There is a way to edit both date and time? If not, how can I contribute to RxDBGrid project to add some features?
Thank you all..

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: RX Library RXDBGrid and TDateTime
« Reply #1 on: May 07, 2021, 11:30:29 am »
Now in the RxFPC library there is no component for editing the date/time field - therefore this is the behavior of the grid. If you have ideas on how to implement such a component - write. I just didn't need it yet.

PS
for PG see my alternative of PgAdmin
https://github.com/lalexs75/FBManager

night builds
http://w7site.ru/fpc/fbm/

andreaboc

  • Newbie
  • Posts: 4
Re: RX Library RXDBGrid and TDateTime
« Reply #2 on: May 10, 2021, 04:46:04 pm »
Hi alexs75,
I just tried the FBManager software and found it very complete and efficient.
Congratulations for your work!

As I expected, connecting FBManager with my DB, the problem on the timestamp field remains: when i try to edit data, the combo for the date appears automatically without the possibility to edit the time and inevitably the information on the time is cleared. For me, make timestamp editable is very important.

I think to proceed i this way: first of all, I will try to create a component to extend TRxDBGrid with an option for choose if DateTime must be edited with a Combo (Ex on OptionExtra dgeUseDateTimePicker), than i will try to write a TDateTimePicker component for timestamp with both date and time.
If you want, I will keep you informed about the work.

PS: There is also the DateTimeCtrls Package for example that have very useful components for DateTime editing.

Thank you.

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: RX Library RXDBGrid and TDateTime
« Reply #3 on: May 12, 2021, 10:39:11 am »
DateTimeCtrls is not a very good time editor. I tend to lean more towards the look and feel of the standard editor. Or by analogy as in Google Chrome. I will think about this topic.

andreaboc

  • Newbie
  • Posts: 4
Re: RX Library RXDBGrid and TDateTime
« Reply #4 on: May 29, 2021, 12:54:48 pm »
For now, I have extended TRxDBGrid with TAsyRxDBGrid Class that overwrite the method:

Code: Pascal  [Select][+][-]
  1. EditorByStyle(Style: TColumnButtonStyle): TWinControl;
  2.  

here the code:

Code: Pascal  [Select][+][-]
  1. unit AsyRxDBGrid;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, LCLType, LCLIntf, Forms, Controls, Buttons,
  9.   Graphics, Dialogs, Grids, DBGrids, DB, PropertyStorage,
  10.   LMessages, types, StdCtrls, Menus, LCLVersion, rxdbgrid;
  11.  
  12. type
  13.  
  14.  
  15.   { TAsyRxDBGrid }
  16.  
  17.   TAsyRxDBGrid = class(TRxDBGrid)
  18.   private
  19.     FTempText : string;
  20.     FStringEditor: TStringCellEditor;
  21.   protected
  22.     procedure UpdateData; override;
  23.     procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
  24.  
  25.   public
  26.     function EditorByStyle(Style: TColumnButtonStyle): TWinControl; override;
  27.     constructor Create(aOwner: TComponent); override;
  28.   published
  29.  
  30.   end;
  31.  
  32. procedure Register;
  33.  
  34. implementation
  35.  
  36. procedure Register;
  37. begin
  38.   {$I asyrxdbgrid_icon.lrs}
  39.   RegisterComponents('Asystel',[TAsyRxDBGrid]);
  40. end;
  41.  
  42. { TAsyRxDBGrid }
  43.  
  44. procedure TAsyRxDBGrid.UpdateData;
  45. var
  46.   edField: TField;
  47. begin
  48.   edField := SelectedField;
  49.   if (edField<>nil) and
  50.      (edField.DataType = ftDateTime) and
  51.      (self.DataSource.DataSet.State in [dsEdit, dsInsert]) then
  52.   begin
  53.     edField.AsDateTime := StrToDateTime(FTempText);
  54.   end else
  55.     inherited UpdateData;
  56. end;
  57.  
  58. procedure TAsyRxDBGrid.SetEditText(ACol, ARow: Longint; const Value: string);
  59. begin
  60.   inherited SetEditText(ACol, ARow, Value);
  61.   FTempText:=Value;
  62. end;
  63.  
  64. function TAsyRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
  65. var
  66.   F: TField;
  67. begin
  68.   if Style = cbsAuto then
  69.   begin
  70.     F := SelectedField;
  71.     if Assigned(F) then
  72.     begin
  73.       if F.DataType in [ftDateTime] then
  74.       begin
  75.         Result := FStringEditor; // for test reason use String editor...
  76.         exit;
  77.       end;
  78.     end;
  79.   end;
  80.  
  81.   Result:=inherited EditorByStyle(Style);
  82. end;
  83.  
  84. constructor TAsyRxDBGrid.Create(aOwner: TComponent);
  85. begin
  86.   Inherited Create(aOwner);
  87.  
  88.   FStringEditor := TStringCellEditor.Create(nil);
  89.   FStringEditor.name :='StringEditor';
  90.   FStringEditor.Text:='';
  91.   FStringEditor.Visible:=False;
  92.   FStringEditor.Align:=alNone;
  93.   FStringEditor.BorderStyle := bsNone;
  94. end;
  95.  
  96. end.
  97.  

In this way, TAsyRxDBGrid handle TDateTime with standard String editor and I can edit both Date and Time.

 

TinyPortal © 2005-2018