修改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.
相关推荐
谢慧琼21 分钟前
2026零基础做企业网站,低成本搭建官方网站
服务器·前端·javascript
weixin_431600442 小时前
前端数据埋点(1):一次点击如何变成一条埋点
前端·js·数据埋点
IT_陈寒2 小时前
Python线程池吞了异常还不告诉我,这谁顶得住啊
前端·人工智能·后端
计算机魔术师2 小时前
同样是AI辅助建造,为什么有的游戏三个月就烂尾了?
前端
用户921080262862 小时前
0. 做 Agent 产品,前端 AI 组件框架怎么选?
前端
拾年2753 小时前
React Hooks 进阶篇:useMemo / useCallback / useReducer / useImperativeHandle,用「算账 +
前端·javascript·react.js
Jackson__3 小时前
面试官:如何在老项目中使用新框架,并实现通信?
前端·javascript·面试
拾年2753 小时前
React Hooks 保姆级教程:把组件想象成失忆的打工人,4 个 Hook 带你原地起飞
前端·javascript·react.js
世人万千丶3 小时前
去重插入与超限淘汰:ArkTS 实现鸿蒙搜索历史的 LIMIT 艺术
运维·服务器·学习·华为·harmonyos·鸿蒙