修改TMS IWAdvWebGrid日期格式

一。 修改两个res文件 tmsiwcal.res 和 tmsiwgridcal.RES

将stgl(sel)函数(选择值放入编辑框)中的这部分修改,设置格式 YYYY-MM-DD ,这是选择日期返回值的格式,res文件大小不能变. (应该有办法转换res文件,取出修改后写回,找找)

TypeScript 复制代码
if (i > 0) {
<#COMPNAME>day = parseInt(s);
if(<#COMPNAME>day < 10) <#COMPNAME>day = '0' + <#COMPNAME>day;
updMonth = parseInt(<#COMPNAME>month) + 1;
if(updMonth < 10) updMonth = '0' + updMonth;
if (<#COMPNAME>format == 0)

二。 修改 IWTMSCal.pas 和 IWWebGrid.pas

查找日期相关部分,修改日期格式,字符串转日期部分的修改,有多处搜索修改

Delphi 复制代码
function TTIWCustomWebGrid.DateStrToDate(AValue: string): TDateTime;
var
  s: string;
  da, mo, ye: word;
  err: Integer;
begin
  Result := Now;
  s := AValue;                                                                         
{ 2004-01-31  和  31-01-2004 只要这两种格式 }
  if pos(FDateSeparator, s) > 0 then
  begin
    val(copy(s, 1, pos(FDateSeparator, s) - 1), ye, err);      { 原da 第一个值修改换成ye}
    delete(s, 1, pos(FDateSeparator, s));                      { 剩两个 01-2004}
    if pos(FDateSeparator, s) > 0 then
    begin
      val(copy(s, 1, pos(FDateSeparator, s) - 1), mo, err);   { 月mo = 01 }
      delete(s, 1, pos(FDateSeparator, s));                   { 剩一个年  2004 }
      val(s, da, err);								    { ye = 2004  无错err为0 }
      if err = 0 then								    { err = 0 如果无错 }
      begin
        if DateFormat = gdEU then
        begin
          Result := EncodeDate(ye, mo, da);
        end
        else
        begin
          Result := EncodeDate(ye, da, mo);  //好像不对,没改,一般不用这种格式
        end;
      end;
    end;
  end;
end;
Delphi 复制代码
function TTIWCalendar.JSDateToDate(AValue: string): TDateTime;   {2024-08-13 Ի     }
var
  s:string;
  da,mo,ye:word;
  err: Integer;
begin
  Result := Now;

  s := AValue;

  if pos('/',s) > 0 then
  begin
    //  从1开始取到/前的字符串,然后转成值 ye , 成功 err = 0   取年份
    val(copy(s,1,pos('/',s)-1),ye,err);   {err == 0,no error}
    delete(s,1,pos('/',s));
    if pos('/',s) > 0 then
    begin
      val(copy(s,1,pos('/',s)-1),mo,err);                     // 取月份
      delete(s,1,pos('/',s));                                 // 删除/前的,只剩日期
      val(s,da,err);                                          //取日期
      if err = 0 then
      begin
        if (mo < 12) then
        begin
          if (daysinmonth(mo + 1,ye) >= da) then
            Result := EncodeDate(ye,mo+1,da)
          else
            Result := EncodeDate(ye,mo+1,daysinmonth(mo + 1,ye));
        end
        else
          Result := 0;
        Day := da;
        Month := mo + 1;
        Year := ye;
      end;
    end;
  end;
end;

修改 function TTIWCustomWebGrid.RenderCalendar 中部分显示格式

TypeScript 复制代码
    if DateFormat = gdEU then
{      html := StringReplace(html, '<#CALVALUE>', IntToStr(Day) + FDateSeparator + IntToStr(Month) + FDateSeparator + IntToStr(Year), [rfReplaceAll, rfIgnoreCase])  2024-08-13修改为下面}
    begin
    var
      FS : TFormatSettings;
      FS.ShortDateFormat:='yyyy-MM-dd';
      html := StringReplace(html, '<#CALVALUE>', DateToStr(EncodeDate(Year,Month,Day),FS), [rfReplaceAll, rfIgnoreCase])
    end

res文件取出查看

Delphi 复制代码
unit Unit1;

{$I DELPHIXE.INC}
{$I TMSDEFS.INC}
interface

{$R tmsiwgrid.res}
{$R tmsiwgridjs.res}
{$R tmsiwgridcal.res}

{$R tmsiwqtip.RES}
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  reshandle: THandle;
  hglobal: THandle;
  ressize: dword;
  ptr: pointer;
  html: string;
  Day, Month, Year: Word;
  p: ansichar;
  CodeDateSeparator: integer;

begin
  reshandle := FindResource(hinstance, 'TMSIWGRID', RT_RCDATA);  // RT_RCDATA = PChar(10); 从res中取代码 然后替换内容
  hglobal := LoadResource(hinstance, reshandle);
  Ressize := SizeOfResource(hinstance, reshandle);
  ptr := LockResource(hglobal);

  Memo1.Clear;
  html := '';
  for i := 1 to ressize do
  begin
    p := ansichar(ptr^);
    html := html + string(p);
    ptr := pointer(integer(ptr) + 1);
  end;
  Memo1.Lines.Add(html);
end;

end.
相关推荐
kejijianwen2 小时前
JdbcTemplate常用方法一览AG网页参数绑定与数据寻址实操
服务器·数据库·oracle
编程零零七2 小时前
Python数据分析工具(三):pymssql的用法
开发语言·前端·数据库·python·oracle·数据分析·pymssql
北岛寒沫3 小时前
JavaScript(JS)学习笔记 1(简单介绍 注释和输入输出语句 变量 数据类型 运算符 流程控制 数组)
javascript·笔记·学习
everyStudy3 小时前
JavaScript如何判断输入的是空格
开发语言·javascript·ecmascript
(⊙o⊙)~哦4 小时前
JavaScript substring() 方法
前端
无心使然云中漫步4 小时前
GIS OGC之WMTS地图服务,通过Capabilities XML描述文档,获取matrixIds,origin,计算resolutions
前端·javascript
Bug缔造者4 小时前
Element-ui el-table 全局表格排序
前端·javascript·vue.js
xnian_5 小时前
解决ruoyi-vue-pro-master框架引入报错,启动报错问题
前端·javascript·vue.js
Karoku0665 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
geek_Chen015 小时前
虚拟机共享文件夹开启后mnt/hgfs/下无sharefiles? --已解决
linux·运维·服务器