LoginSignup
0
1

More than 5 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo > TStringGrid > csv文字列をセルに追加する実装

Last updated at Posted at 2017-04-13
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

csv文字列をTStringGridの最後の行に追加する実装。

#include <memory>

// 中略

void __fastcall TFormUserList::addLine(String csvline, TStringGrid *dstPtr)
{
    if (dstPtr == NULL) {
        return; // error
    }

    std::unique_ptr<TStringList> line (new TStringList);

    line->StrictDelimiter = true;
    line->Delimiter = L',';
    line->DelimitedText = csvline;

    int last = dstPtr->RowCount;
    dstPtr->RowCount = last + 1;

    for(int idx=0; idx < line->Count; idx++) {
        dstPtr->Cells[idx][last - 1] = line->Strings[idx];
    }
    dstPtr->Refresh();
}

使用例

(追記 2018/10/17)

以下のような使い方ができる。

addLine(L"PI,3.141592", StringGrid1);
addLine(L"Napier,2.7182", StringGrid1);
addLine(L"Avogadro,6.0221023", StringGrid1);
0
1
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
1