修改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.
相关推荐
字节高级特工5 分钟前
深入探索Linux:忙碌的车间“进程”间通信
linux·运维·服务器
帅帅梓22 分钟前
linux远程控制
linux·运维·服务器
香蕉可乐荷包蛋1 小时前
排序算法 (Sorting Algorithms)-JS示例
javascript·算法·排序算法
格调UI成品1 小时前
元宇宙工厂前端新形态:Three.js与WebGL实现3D产线交互的轻量化之路
前端·javascript·webgl
gnip1 小时前
微前端框架选型
前端·javascript
芒果1251 小时前
【转载文章】ECharts-GL 实现世界级、国家级、省市级 3D 地图
前端
一只小风华~2 小时前
JavaScript:数组常用操作方法的总结表格
前端·javascript·数据结构·vue.js·算法
前端老鹰2 小时前
JavaScript Array.prototype.some ():数组判断的 “快捷侦探”
前端·javascript
张元清2 小时前
揭秘JS事件循环:一道字节跳动面试题带你深入理解async/await、Promise与RAF
前端·react.js·面试
KenXu2 小时前
F2C-Chrome插件-Figma免费的DevMode来了!
前端