お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"レコード型リスト ユニット(interface)"

この発言は
#01393 HATENA さんのレコード型を動的配列で管理するクラス
に対するコメントです

{******************************************************************* 固定長レコードのリストの管理クラス function Add(Item: TMyRec): Integer; レコードを追加します。追加した位置のインデックスを返します。 Sorted = True の場合は、ソートを保つ位置に挿入します。 procedure Delete(Index, ACount: Integer); Index位置から、ACount分のレコードを削除します。 procedure Exchange(Index1, Index2: Integer); リスト内の 2 つのレコードの位置を入れ替えます。 Sorted = True の場合は、ソートキーが同じレコードを入れ替えるとき以外は 使用しないで下さい。 function Expand: TRecList; リストの Capacity プロパティの値を拡張します。 function Find(const AMyRec: TMyRec; var Index: Integer): Boolean; ソートされたリスト内のレコードのIndexを特定し,そのソートキーを持つ レコードすでにリストに存在するかどうかを示します。 procedure Insert(Index: Integer; const Item: TMyRec); リスト内の Index が指定する位置にレコードを挿入します。 Sorted = True のときは例外を生成します。 procedure LoadFromFile(const FileName: string); 指定したファイルのレコードデータをリストに取得します。 procedure Move(CurIndex, NewIndex: Integer); リスト内のレコードの位置を変更します。 Sorted = True のときは例外を生成します。 procedure SaveToFile(const FileName: string); リストのレコード配列を指定したファイルに保存します。 procedure Sort(Compare: TArraySortCompare); 比較関数 Compare に基づいてリストのクイックソートを行います。 property Capacity: Integer read FCapacity write SetCapacity; レコードを保持する動的配列の割り当てサイズを指定します。 property Count: Integer read FCount write SetCount; リスト内のレコードの数を示します。 property Items[Index: Integer]: TMyRec read Get write Put; default; レコードの参照をリストで表示します。 property RecArray: TMyRecArray read FRecArray; レコードを保持する動的配列を参照します。 property Sorted: Boolean read FSorted write SetSorted; リストのレコードを自動的に並べ替えるかどうかを指定します。 property SortCompare: TArraySortCompare read FCompare write SetSortCompare; Sorted = True のとき、並べ替えに使用する比較関数を指定します。 ************************************************************************} unit Unit2; interface uses Classes, SysUtils, Windows; const CTime = 24 * 60; type { TRecList class } TMyRec = Record Date: Integer; StartTime: Word; EndTime: Word; Title: String[19]; end; TMyRecArray = array of TMyRec; TArraySortCompare = function (Item1, Item2: TMyRec): Integer; TRecList = class(TObject) private FRecArray: TMyRecArray; FCount: Integer; FCapacity: Integer; FCompare: TArraySortCompare; FSorted: Boolean; procedure InsertItem(Index: Integer; const Item: TMyRec); protected function Get(Index: Integer): TMyRec; procedure Grow; virtual; procedure Put(Index: Integer; Item: TMyRec); procedure SetCapacity(NewCapacity: Integer); procedure SetCount(NewCount: Integer); procedure SetSorted(Value: Boolean); procedure SetSortCompare(ACompare: TArraySortCompare); public destructor Destroy; override; function Add(Item: TMyRec): Integer; procedure Clear; procedure Delete(Index, ACount: Integer); procedure Exchange(Index1, Index2: Integer); function Expand: TRecList; function Find(const AMyRec: TMyRec; var Index: Integer): Boolean; procedure Insert(Index: Integer; const Item: TMyRec); procedure LoadFromFile(const FileName: string); procedure Move(CurIndex, NewIndex: Integer); procedure SaveToFile(const FileName: string); procedure Sort(Compare: TArraySortCompare); property Capacity: Integer read FCapacity write SetCapacity; property Count: Integer read FCount write SetCount; property Items[Index: Integer]: TMyRec read Get write Put; default; property RecArray: TMyRecArray read FRecArray; property Sorted: Boolean read FSorted write SetSorted; property SortCompare: TArraySortCompare read FCompare write SetSortCompare; end; 01/10/09(火) 12:30 HATENA(GFC03235)  Original document by HATENA 氏 ID:(GFC03235)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum