// 以下範例以二維陣列或無向圖 (undirected graph) 的相鄰成本矩陣說明
// 得先自工具列 Additional 項目/TStringGrid 中, 拉出 StringGrid1 放在某顯示畫面 (可能是某個 PageControl/Tab 中,如下圖)
for (i=0; i<n; i++)
{ for (j=i+1; j<n; j++)
{ W[i][j] = rand()%range + 1;
if (W[i][j] > max_range) W[i][j] = LargeInt;
W[j][i] = W[i][j];
}
W[i][i] = LargeInt;
} // 亂數產生二維對稱的相鄰成本矩陣
// 以下將 W 陣列放入 StringGrid1 中顯示
StringGrid1->RowCount = n;
StringGrid1->ColCount = n;
for (i=0; i<n; i++)
{ for (j=0; j<n; j++)
{ StringGrid1->Cells[j][i] = IntToStr(W[i][j]);
// VS C++ 語法則用: StringGrid1->Rows[i]->Cells[j]->Value = W[i][j];
}
} // 以 StringGrid 顯示相鄰成本矩陣
下面是一份有關 StringGrid 用法的文件: