DBGrid formatting for column with a date lazarus / 31-LCL ---------------------------------------------------------------------- mcculloch · 2019-11-28 01:40 I'd like to format two date columns in a TDBGrid.  When I set the display format for the columns, it applies the format successfully to the design time columns.  The run time columns are different than the default design format and my defined format.  How do I set the displayformat that is used at runtime?  I have a format on a float that works fine at design time and runtime. ---------------------------------------------------------------------- fmc · 2019-11-28 02:01 Add two Columns to the DBGrid using your Object Inspector.  Select the ellipses in the Column properties, then add two Title fields. Notice above the Object Inspector two Column properties showed up in the Component Tree. Click the first one in that tree. Then in your Object Inspector, set the DisplayFormat to yyyy/mm/dd (or however you want it to look), then set the FieldName property to one of your DateFields. Next, scroll down to Title, expand it, set the Caption you want on the TitleBar of your DBGrid. ---------------------------------------------------------------------- mcculloch · 2019-11-28 02:17 Thanks but that's where I am now.  I have all of that but it doesn't apply the same format at run time that it applies at design time. ---------------------------------------------------------------------- fmc · 2019-11-28 02:32 I don't know what to say then. I just tested a DateField with yyyy/mm/dd and mm/dd/yyyy and dd/mm/yyyy and they all displayed as per the DisplayFormat. Not sure what you have going on. ---------------------------------------------------------------------- valdir.marcos · 2019-11-28 10:02 Quote from: mcculloch on November 28, 2019, 02:40:11 amI'd like to format two date columns in a TDBGrid.  When I set the display format for the columns, it applies the format successfully to the design time columns.  The run time columns are different than the default design format and my defined format.  How do I set the displayformat that is used at runtime?  I have a format on a float that works fine at design time and runtime.Quote from: fmc on November 28, 2019, 03:01:23 amAdd two Columns to the DBGrid using your Object Inspector.  Select the ellipses in the Column properties, then add two Title fields. Notice above the Object Inspector two Column properties showed up in the Component Tree. Click the first one in that tree. Then in your Object Inspector, set the DisplayFormat to yyyy/mm/dd (or however you want it to look), then set the FieldName property to one of your DateFields. Next, scroll down to Title, expand it, set the Caption you want on the TitleBar of your DBGrid.Quote from: mcculloch on November 28, 2019, 03:17:01 amThanks but that's where I am now.  I have all of that but it doesn't apply the same format at run time that it applies at design time.Quote from: fmc on November 28, 2019, 03:32:49 amI don't know what to say then. I just tested a DateField with yyyy/mm/dd and mm/dd/yyyy and dd/mm/yyyy and they all displayed as per the DisplayFormat. Not sure what you have going on.Please, prepare and attach a small sample project and also attach a image of that date format at design time and another image of the same date format at run time. It's difficult to help you without understand what you are really going through. ---------------------------------------------------------------------- mcculloch · 2019-11-28 23:53 I made a zip file with the project and a screen shot.  I left out the lib and backup directory and it was still too big so I left out the screen shot.  (250K limit?  Really?)  All the screen shot showed was a design time window and a runtime window showing different formats for the date columns.  Let me know if you need to see the screen shot.  It's still too big even all by itself so I'll have to figure out something else. ---------------------------------------------------------------------- winni · 2019-11-29 00:13 Hi ! I can't compile the project due to missing libs, but: dbGridSecurities --> Object Inspector --> Options dgColumResize is enabled. Disable it. Perhaps this is just the reason. Winni ---------------------------------------------------------------------- valdir.marcos · 2019-11-29 12:08 Quote from: mcculloch on November 29, 2019, 12:53:15 amI made a zip file with the project and a screen shot.  I left out the lib and backup directory and it was still too big so I left out the screen shot.  (250K limit?  Really?)  All the screen shot showed was a design time window and a runtime window showing different formats for the date columns.  Let me know if you need to see the screen shot.  It's still too big even all by itself so I'll have to figure out something else.I have opened you small sample project and to my surprise there is no sample database file to test it and you misplaced the database components outside of the obvious visible screen. Please, check the attached images. Looking to your "unit_securities.lfm", why have you set DisplayFormat on TDBGrid instead of on TSQLQuery? Please, first remove DisplayFormat information from TDBGrid, then add it to TSQLQuery fields and test your project again both on design and run time. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object FormSecurities: TFormSecurities  Left = -34  Height = 384  Top = 188  Width = 1028  Caption = 'Securities'  ClientHeight = 384  ClientWidth = 1028  LCLVersion = '2.0.7.0'  object dbgridSecurities: TDBGrid    Left = 64    Height = 166    Top = 72    Width = 967    Color = clWindow    Columns = <          item        Title.Caption = 'Symbol'        FieldName = 'symbol'      end          item        Title.Caption = 'Description'        Width = 350        FieldName = 'description'    end          item        Title.Caption = 'Ex-dividend Date'        FieldName = 'ex_div_date'        **********************************      **  DisplayFormat = 'mm/dd/yy'  **        **********************************      end          item        Title.Caption = 'Dividend Date'        FieldName = 'div_date'        DisplayFormat = 'mm/dd/yy'      end          item        Title.Caption = 'Yield'        FieldName = 'yield'        DisplayFormat = '0.00%'    end>    DataSource = dataSecurities    TabOrder = 0  end  object sqlconnSecurities: TMySQL57Connection    Connected = False    LoginPrompt = False    DatabaseName = 'investments'    KeepConnection = False    Password = 'JWM&Bear'    Transaction = sqltransSecurities  UserName = 'john'    HostName = 'server01.local'    SkipLibraryVersionCheck = False    Left = 72    Top = 757  end  object sqltransSecurities: TSQLTransaction    Active = False    Database = sqlconnSecurities    Left = 200    Top = 757  end  object sqlqrySecurities: TSQLQuery    IndexName = 'DEFAULT_ORDER'    FieldDefs = <          item        Name = 'symbol'        DataType = ftString        Precision = -1        Size = 12      end          item        Name = 'description'        DataType = ftString        Precision = -1        Size = 60      end          item        Name = 'ex_div_date'        DataType = ftDate        Precision = -1        **********************************        **  DisplayFormat = nothing   **        **********************************      end          item        Name = 'div_date'        DataType = ftDate        Precision = -1      end          item        Name = 'yield'        DataType = ftFloat        Precision = -1      end>    Database = sqlconnSecurities    Transaction = sqltransSecurities    SQL.Strings = (      'SELECT * FROM securities ORDER BY symbol'    )    Params = <>    Left = 352    Top = 760  end  object dataSecurities: TDataSource    DataSet = sqlqrySecurities    Left = 496    Top = 757  endend ---------------------------------------------------------------------- mcculloch · 2019-11-29 13:35 I just went with what I saw in the object inspector.  There's no such property on the object inspector where you show "DisplayFormat = nothing".  Under Precision = -1 there is only Size = 0.  Should I edit .lfm file directly?  How do I add this? And there is no sample database file since the database I'm using is not a file.  I'm using MySQL.   Also, the database components may be off the window since I attempted to fit both the design time and run time window on the screen for the screen shot which unfortunately is too big to attach. Please don't waste any more time on this.  I only found Lazarus about a month ago after looking for an open source analog of Delphi for PHP.  I had Delphi back in the early '90s and found it great for small projects.  I learned Pascal in college starting in 1980 and thought that Borland had done great things with Turbo Pascal for Windows around 1990 which became Delphi soon after.  I am really more interested in web for user interface.  That's why I was looking for open source alternatives to Delphi for PHP.  Thanks to all who tried to help. ---------------------------------------------------------------------- valdir.marcos · 2019-11-30 05:18 Quote from: mcculloch on November 29, 2019, 02:35:08 pmI just went with what I saw in the object inspector.  There's no such property on the object inspector where you show "DisplayFormat = nothing".  Under Precision = -1 there is only Size = 0.  Should I edit .lfm file directly?  How do I add this?Please, check the attached image. 5. Right click on the SQLQuery component to access the field editor; 6. Right click on the field editor blank area to add one, some or all fields; 7. Click on Create button; 8. Click on the chosen field, then you will see the DisplayFormat properties for numeric fields. More information: Data controls based on the field editor... https://forum.lazarus.freepascal.org/index.php?topic=40748.0 How to replace the field type and value in dbgrid? https://forum.lazarus.freepascal.org/index.php/topic,40674.0.html Drag and drop from the fields editor to the form to dynamically create fields on form at design time. https://bugs.freepascal.org/view.php?id=33555 QuoteAnd there is no sample database file since the database I'm using is not a file.  I'm using MySQL.Providing an SQL script would solve that. For instance: Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i CREATE TABLE xyz(  id       INTEGER PRIMARY KEY,   name VARCHAR(40));commit; INSERT INTO xyz(name) VALUES('abc');commit;QuoteAlso, the database components may be off the window since I attempted to fit both the design time and run time window on the screen for the screen shot which unfortunately is too big to attach.Internet is plenty of sites to shrink image sizes. For example: https://www.easy-resize.com/ QuotePlease don't waste any more time on this. I only found Lazarus about a month ago after looking for an open source analog of Delphi for PHP.As far as I can remember,  CodeGear Delphi for PHP 1.0 was released in 2007 and died soon after as Embarcadero RadPHP XE2 in 2011. https://edn.embarcadero.com/article/34059 https://en.wikipedia.org/wiki/Delphi_(software) https://delphi.fandom.com/wiki/Delphi_for_PHP http://docwiki.embarcadero.com/RadPHP/en/Main_Page https://support.embarcadero.com/article/38899 https://www.wikiwand.com/en/Delphi_(software) https://en.wikipedia.org/wiki/RadPHP QuoteI had Delphi back in the early '90s and found it great for small projects. I learned Pascal in college starting in 1980 and thought that Borland had done great things with Turbo Pascal for Windows around 1990 which became Delphi soon after. I am really more interested in web for user interface. That's why I was looking for open source alternatives to Delphi for PHP.Whatever you need, there are alternatives using Free Pascal and Lazarus: The future of the Lazarus IDE https://forum.lazarus.freepascal.org/index.php/topic,47506.0.html Modern UI in Lazarus https://forum.lazarus.freepascal.org/index.php/topic,36502.msg339987.h tml#msg339987 Create Web App https://forum.lazarus.freepascal.org/index.php/topic,47439.0.html WebServices on Lazarus/FPC https://forum.lazarus.freepascal.org/index.php/topic,47132.0.html handling https with managed lazarus http server https://forum.lazarus.freepascal.org/index.php/topic,46906.0.html TMS Web Core vs. Elevate Web Builder vs, FMSoft UniGUI vs. VirtualUI vs. ? https://forum.lazarus.freepascal.org/index.php/topic,44636.0.html QuoteThanks to all who tried to help.You're welcome. ---------------------------------------------------------------------- mcculloch · 2019-12-01 21:40 I was going to give up on this but your answers were so good I gave your suggestions one more attempt.  When I add the field to the query object, it adds them "along side" of the FieldDefs array I already had.  So I didn't understand the difference between the fields in the FieldDefs property and the ones using your method.  But, much more importantly, just after I do that, if I click on anything in the object inspector I get access violations and I have to abort the program.  I'm using version 1.8.2 under Ubuntu 18.04. I took a screen shot of my project after adding the fields, showing both sets of field definitions in both places.  Unfortunately, it won't compress small enough to post.  Either way, I'm done now. ---------------------------------------------------------------------- valdir.marcos · 2019-12-02 01:33 Quote from: mcculloch on December 01, 2019, 10:40:05 pmI was going to give up on this but your answers were so good I gave your suggestions one more attempt. Thank you. We are trying to help you. QuoteWhen I add the field to the query object, it adds them "along side" of the FieldDefs array I already had.  So I didn't understand the difference between the fields in the FieldDefs property and the ones using your method. But, much more importantly, just after I do that, if I click on anything in the object inspector I get access violations and I have to abort the program.It's difficult to understand your problem without a small sample project that shows those error messages you are going through. QuoteI'm using version 1.8.2 under Ubuntu 18.04. I took a screen shot of my project after adding the fields, showing both sets of field definitions in both places. Unfortunately, it won't compress small enough to post. Either way, I'm done now.My suggestion is: open your mind to a new world. Just for a moment, stop what you are doing, and get yourself some time to learn a new way of doing things: https://wiki.freepascal.org/Databases https://www.youtube.com/results?search_query=free+pascal+lazarus After that review, start a new project from scratch to test what you have just learned. In case of new problems, attach a small sample project so we can better help you. ---------------------------------------------------------------------- mcculloch · 2019-12-02 13:00 My suggestion to whomever maintains this forum is to raise the attachment size limit. ---------------------------------------------------------------------- wp · 2019-12-02 14:38 Quote from: mcculloch on December 02, 2019, 02:00:09 pmMy suggestion to whomever maintains this forum is to raise the attachment size limit. (I am not the forum maintainer, but:) Don't include compiler-generated files in the attachment. For source code projects (and this is why attachments are good for here) it is mostly sufficient to include the *.pas, *.lfm, *.lpi and .lpr files plus maybe data files. Dont't include the generated binary and ppu, o, res, ico etc files. This way the zipped size will stay well below the 250 kB.