Recent

Author Topic: Cell formatting question  (Read 1533 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Cell formatting question
« on: February 01, 2022, 11:20:10 pm »
Hi,

A quick question.

If I format a cell with, say
Code: Pascal  [Select][+][-]
  1. Grid.NumberFormat[1,20] := 'mmm/yy';
would there be any difference if I typed in that cell or set the contents of the cell in code?

It seems, unless I've got something wrong, that if I type, say 1/12/21, I get what I would expect, Dec/21. But, if I set the cell contents to '1/12/21' with
Code: Pascal  [Select][+][-]
  1. Grid.cells[1,20]:= '1/12/21';
all I get is 1/12/21, the formatting doesn't seem to take effect.

Is this correct?

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 10281
Re: Cell formatting question
« Reply #1 on: February 02, 2022, 12:59:17 am »
Code: Pascal  [Select][+][-]
  1. Grid.cells[1,20]:= '1/12/21';
all I get is 1/12/21, the formatting doesn't seem to take effect.
Doing this puts a string into the cell - there is no attempt to convert it to a date. But when you assign a TDateTime it works:
Code: Pascal  [Select][+][-]
  1. Grid.Cells[1,20] := EncodeDate(2021, 1, 12);

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Cell formatting question
« Reply #2 on: February 02, 2022, 10:33:57 am »
Hi wp,

Yes it does't attempt to put a string into the cell, so I will change it to a TDateTime and give it a try.

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018