修改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.
相关推荐
梦曦i4 小时前
@meng-xi/create-uni-app vs unibest:轻量脚手架与重型框架的定位之争
前端·uni-app
平头哥技术团队4 小时前
Day 10 | 工欲善其事:VS Code 配置与项目归档
android·开发语言·前端·javascript·html·交互
乌恩大侠4 小时前
GH200 新增 NVMe SSD 分区、格式化与挂载完整流程
运维·服务器·前端
yume_sibai4 小时前
Element Plus 数据展示组件完全指南(15个核心组件)
前端·javascript·vue.js
Mr.朱鹏5 小时前
Linux 服务器 LVM 根分区在线动态扩容
linux·服务器·数据库
qiuhaipeng15 小时前
Claude code 升级后上下文长度变短问题
java·前端·数据库
mengge.cloud5 小时前
存储技术基础小白教程
linux·运维·服务器·wpf·存储
zzz_23685 小时前
个人 AI 记忆如何跨工具复用:用 Markdown、索引和 Skill 搭一个可治理的记忆库
前端·人工智能·react.js·前端框架·agent·agent测评
tang777896 小时前
反爬虫场景下代理IP池的动态扩容与失效IP自动清理方案实现
linux·服务器·网络·爬虫代理·住宅代理ip
剑之所向7 小时前
.NET 官方`System.Threading.Channels`
前端·javascript·数据库