LoginSignup
0
0

More than 3 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > TMemo > Error: nilをTMemoStringsに代入することはできません。

Last updated at Posted at 2017-10-18
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/05)

qiita.png

発生条件は以下のような処理だった。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TStringList *list = NULL;

    Memo1->Lines->Assign(list);
}
//---------------------------------------------------------------------------

本来はlistにポインタの値が割当てられるように実装していたが、プロジェクトの構成を見直した時に一旦NULLを入れるようにした。
その時点でエラーが出た。

Assignなどの割当て処理は本来try, catchできちんと処理して、おかしな実装の場合は開発者向けメッセージとして表示するようにした方がいい。

0
0
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
0
0