You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Delphi如何遍历packed record字段无需逐个指定字段名

Delphi Packed Record字段遍历与序列化版本控制实现

开发环境

  • 适配Delphi版本:Sydney、Alexandria

定义的结构体代码

type
  PFileList = ^TFileList;
  TFileList = Packed Record
    ProfileName: string;
    ProfileDescription: string;
    ProfileMemo: string;
    CustomURL: string;
    SSOProperties: string;
  end;
type
  TArrOfFileList = array of TFileList;

需求说明

现有TArrOfFileList类型变量FProfileModel,需要在不逐个书写FProfileModel[0].ProfileName、FProfileModel[0].ProfileDescription这类字段名的前提下,遍历TFileList结构的所有字段,获取该记录的字段总数,用于后续类型迁移。
当前已基于UkDynamic组件实现结构体数组的文件序列化,代码如下:

procedure SaveProfile(const fs: string; var array1: 
  TArrOfFileList);
var
  Stream: TFileStream;
begin
   Stream := TFileStream.Create( fs, fmCreate);
   try
     TKBDynamic.WriteTo(Stream, array1, 
       TypeInfo(TArrOfFileList));
   finally
     Stream.Free;
   end;
end;

最终解决方案

参考@SilverWarior的提示,扩展UkDynamic组件的序列化逻辑,为文件存储的记录新增版本控制机制,需求已实现。

内容的提问来源于stack exchange,提问作者user14409582

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 03:15:00