2012년 10월 12일 금요일

리스트 뷰에 데이터 저장하기

리스트 뷰도 리스트 박스와 같이 스트링을 저장하되 여러 컬럼을 보이게 할 수 있습니다.
스트링을 저장하기 위하여는 먼저 컬럼을 생성하여 주고 ViewStyle 을 bsReport로 바꾸고
(이해가 쉽도록), 컬럼을 생성합니다.

var
  iColumn: TListColumn;
begin
  iColumn:= ListView1.Columns.Add;
  iColumn.Caption:= '번호';
  iColumn:= ListView1.Columns.Add;
  icolumn.Caption:= '이름';
  iColumn.Width:= 200;
end;

스트링 값을 저장하기 위하여

var
  iListItem: TListItem;
begin
  iListItem:= ListView1.Items.Add;
  iListItem.Caption:= edit2.Text;
  iListItem.SubItems.Add(Edit1.Text);
end;

와 같이하고, 현재 선택된 리스트의 값을 읽어오기 위하여
var
  iListItem : TListItem;
begin
   if ListView1.Selected <> nil then begin
     iListItem := ListView1.Selected;
     edit1.Text:= iListItem.SubItems[0];
     edit2.Text:= iListItem.Caption;
  end;   
end;

그럼 이전과 같은 방법으로 객체를 저장하여 봅시다.

var iMyObject: TMyObject;
begin
  iMyObject:= TMyObject.Create(StrToInt(Edit1.Text), Edit2.Text);
  ListView1.AddItem(iMyObject.Name, iMyObject);
end;

읽어 오기 위하여 TListItem 의 Caption, Data Property 를 사용합니다.
ListBox 에서는 Strings.Object 를 사용하였던것을 상기 하십시요.

var
  iListView: TListItem;
begin
  if  ListView1.Selected <> nil then begin
     iListView:= ListView1.Items[ListView1.ItemIndex];
     Edit1.Text:= IntToStr(TMyObject(iListView.Data).no);
     Edit2.Text:= TMyObject(iListView.Data).Name;
  end;
end;

Listview.SortTYpe := stText 로 하면 자동 정열이 됩니다.

멀티 컬럼 형식에서 저장하려면 ?

var iMyObject: TMyObject;
  iListItem: TListItem;
begin
  iMyObject:= TMyObject.Create(StrToInt(Edit1.Text), Edit2.Text);
  iListItem:= ListView1.Items.Add;
  iListItem.Caption:= IntToStr(iMyObject.No);
  iListItem.SubItems.AddObject(iMyObject.Name, iMyObject);
end;

과 같이하면 되겠습니다.

이말은 객체의 보여 주는 부분은 iListItem.Caption 과 SubUtems.Add 하고
마지막 보여 지는 컬럼에서 SubItems.AddObject() 하면 되겠습니다.

// 종료시 object를 Free 해주어야 하는데...

댓글 없음:

tensorflow gpu 사용하기에서

 tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...