掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
TListに格納したメモリの開放について (ID:9041)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
TListを継承し、recordをリスト管理するクラスを作成しています。 RecList (TListを継承して作成したクラスTRecListのインスタンス) で 『値 := RecList.Items[Index].レコードのメンバ変数;』といった感じにrecordにアクセスしたいのです。 しかし、Itemsの戻り値をポインタで無く、TRecord型にしているため、 TRecListに格納しているrecordポインタ型のメモリを開放出来ません。 文書だけでは分かりづらいと思いますので、 以下に簡易版のソースを書きますので、どなたかよい対応方法をご教授下さい。 --------------------------------------------------------------- PRecord = ^TRecord; TRecord = record メンバ省略 end; type TRecList = Class(TList) public property SetRec(); property Items[Index : Integer] : TRecord read Get; default; procedure Delete(Index : Integer); end; function SetRec(); //リスト化するレコードのポインタを格納 var Rec : PRecord; begin new(Rec); Rec^.メンバ := 格納値; TRecList(Self).Add(Rec); end; function TRecList.Get(Index : Integer) : TRecord; //Indexのレコードを返す Result := PRecord(inherited Get(Index))^; end; procedure Delete(Index : Integer); begin Dispose(PRecord(TRecList(Self).Items[Index])); ↑ Itemsの戻り値はTRecord型なのでDispose出来ない! end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.