お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





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

"TLightStringsの拡張"




べあさんのTLightStringsクラス(軽量文字列リスト)にTStringList互換の
プロパティなどをいくつか追加します。
TLightStringsは nifty:FDELPHI/LIB/5/75にまだあるはずです。

//--------( 宣言 )----------------
  private
    // 追加プロパティへのアクセスメソッド
    function GetName(Index: Integer): string;
    function GetValue(const Name: string): string;
    procedure SetValue(const Name, Value: string);
  public
    // AddStringsがTStrings型の文字列リストを一括追加するのに
    // 対してAddLightStrはTLightStrings型の文字列を扱う。
    procedure AddLightStr(Source:TLightStrings);
    // 以下はTStringsと同じです。
    function IndexOfName(const Name: string): Integer;
    property Names[Index: Integer]: string read GetName;
    property Values[const Name: string]: string read GetValue
      write SetValue;

//--------( 実装 )----------------

// AddStringsとはパラメータの型が違うだけ
procedure TLightStrings.AddLightStr(Source:TLightStrings);
var C,I:Integer;
begin
  C:=Source.Count;
  SetCapacity(Count+C);
  for I:=0 to Source.Count-1 do Add(Source[i]);
end;

// Classes.pasのソースからいただき(以下同文)
function TLightStrings.GetName(Index: Integer): string;
var
  P: Integer;
begin
  Result := Get(Index);
  P := AnsiPos('=', Result);
  if P <> 0 then
    SetLength(Result, P-1) else
    SetLength(Result, 0);
end;

function TLightStrings.IndexOfName(const Name: string): Integer;
var
  P: Integer;
  S: string;
begin
  for Result := 0 to FCount - 1 do
  begin
    S := Get(Result);
    P := AnsiPos('=', S);
    if (P<>0) and (AnsiCompareText(Copy(S,1,P-1), Name) = 0) then Exit;
  end;
  Result := -1;
end;

function TLightStrings.GetValue(const Name: string): string;
var
  I: Integer;
begin
  I := IndexOfName(Name);
  if I >= 0 then
    Result := Copy(Get(I), Length(Name) + 2, MaxInt) else
    Result := '';
end;

                  http://member.nifty.ne.jp/h-triton/
          ○ 快速・大容量テキストエディタ「えるの〜と」進化中 ○
          Avalon's Friendly Crew #80008  H-Triton (^^) since 1996

Original document by H-Triton        氏 ID:(QZV11422)


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

Copyright 1996-2002 Delphi Users' Forum