3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

生成・解放のtry…finallyが多階層すぎてやぁ~ん→1階層で済んですっきり

Last updated at Posted at 2014-03-13

生成・解放のtry…finallyが多階層すぎてやぁ~ん!

  wStringList1 := TStringList.Create;
  try
    wStringList2 := TStringList.Create;
    try
      wStringList3 := TStringList.Create;
      try
        //----------------
        //処理ごにょごにょ
        //----------------
      finally
        wStringList3.Free;
      end;
    finally
      wStringList2.Free;
    end;
  finally
    wStringList1.Free;
  end;

1階層で済んですっきり

  wStringList1 := nil;
  wStringList2 := nil;
  wStringList3 := nil;
  try
    wStringList1 := TStringList.Create;
    wStringList2 := TStringList.Create;
    wStringList3 := TStringList.Create;
    //----------------
    //処理ごにょごにょ
    //----------------
  finally
    //Freeメソッドは、nil入ってる場合は無視してくれる
    wStringList3.Free;
    wStringList2.Free;
    wStringList1.Free;
  end;

めでたしめでたし…おしまいっ☆彡

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?