掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Record型のフィールド数を求めるには? (ID:42104)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
XE2の場合、下記方法でとりあえず取得できましたが、2007では分かりません。 uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, TypInfo; type TTest = packed record w, x, y, z: Integer; end; TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private 宣言 } public { Public 宣言 } pt: TTest; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var pti: PTypeInfo; ptd: PTypeData; pNumOps: PByte; pRecFldCnt: PInteger; begin Memo1.Clear; pti := TypeInfo(TTest); Memo1.Lines.Add(Format('%s(%d)', [String(pti.Name), Integer(pti.Kind)])); ptd := GetTypeData(pti); // tkRecord: ( // RecSize: Integer; // ManagedFldCount: Integer; // {ManagedFields: array[0..ManagedFldCnt - 1] of TManagedField; // NumOps: Byte; // RecOps: array[1..NumOps] of Pointer; // RecFldCnt: Integer; // RecFields: array[1..RecFldCnt] of TRecordTypeField; // RecAttrData: TAttrData; // RecMethCnt: Word; // RecMeths: array[1..RecMethCnt] of TRecordTypeMethod}); Memo1.Lines.Add(Format('RecSize = %d', [ptd.RecSize])); pNumOps := PByte(ptd)+SizeOf(Integer)*2+SizeOf(TManagedField)*ptd.ManagedFldCount; pRecFldCnt := PInteger(pNumOps+SizeOf(pNumOps^)+SizeOf(Pointer)*pNumOps^); Memo1.Lines.Add(Format('RecFldCnt = %d', [pRecFldCnt^])); end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.