お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





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

"履歴管理クラス"

この発言に対し以下のコメントが寄せられています
#01023 本田勝彦 さん RE:履歴管理クラス

みなさん、おはようございます。 Diaです。  nifty:FDELPHI/MES/06/30236で話題になった、二次元座標の移動を 管理するクラスです。  別に早いわけでもなければすごいことをやってるわけでもありませんが、 PointList := TPointList.create(limit); とやってインスタンスを作って、 PointList.addData(Data); とやれば、座標Dataをどんどこため込みます。 limitを越えると古いものは勝手に廃棄しますので、 常に最新の数十個だけを保持します。 取り出すときは PointList.data[番号]で取り出せます。  メモリの確保とかは中で面倒を見るので、最後はPointList.Free;してしまえば 後腐れなく死んでくれるのが気に入ってます。 TPointList = class(TList) //データ型を保持するためのリスト。 //メモリの確保、廃棄を自動で行う。 protected Flimit: integer; public destructor Destroy; override; constructor create(limit:integer); function AddData(Data: TPoint): Integer; procedure Clear; override; procedure Delete(Index: Integer); function getData(Index:integer):TPoint; property Data[Index: Integer]:TPoint read GetData; property limit:integer read Flimit; end; implementation { TPointList } function TPointList.AddData(Data: TPoint): Integer; var NewData:PPoint; begin if count+1 > limit then Delete(0); new(NewData); NewData^.x := Data.x; NewData^.y := Data.y; result := inherited add(NewData); end; procedure TPointList.Clear; var i:integer; begin for i:= 0 to count-1 do begin Delete(0); end; inherited clear; end; constructor TPointList.create(limit: integer); begin inherited create; FLimit := limit; Capacity := limit+1; end; procedure TPointList.Delete(Index: Integer); begin Dispose(Items[Index]); Items[Index] := nil; inherited Delete(Index); end; destructor TPointList.Destroy; var i:integer; begin for i:= 0 to count-1 do begin Delete(0); end; inherited Destroy; end; function TPointList.getData(Index: integer): TPoint; begin result := TPoint(Items[Index]^); end; end.                  しっぽを引くと、もぎゃあと鳴きます。                    daisuke.furukawa@nifty.ne.jp Dia   Original document by Dia 氏 ID:(CQK00014)



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

Copyright 1996-2002 Delphi Users' Forum