Mgiho란 EDIT박스 내용으로 검색한 결과를 Lbiname이란
리스트박스에 보여주는 소스입니다.
그런데 Mgiho의 내용이 자리수가 적어지면 똑바로 정렬이 안되는군요.
예를 들어 12345678 이란 8자리수는 공백이 제대로 먹고 1234란 4자리 수에서는
공백이 다먹지 않습니다.
그리고 'no1' 이란 필드에 저장된 1,2,3을 Mgu.text(콤보박스)의 아이템(교수,학생,
조교)으로 바꾸는건 가능한데 저장하는 방법은 모르겠습니다.
아무리 발버둥을 쳐도 방법이 없군요.
역시 가르침 부탁드립니다.
procedure TFrmJohap.MgihoKeyPress(Sender: TObject; var Key: Char);
var
i: Byte;
m_giho: String[10];
m_gubun: String[4];
begin
if Key = #13 then // Enter를 치면
begin
if Mgiho.Text = '' then // 이름에 입력하지 않고 enter를 쳤을 경우
begin
mname.SetFocus;
exit;
end;
with Query1 do
begin // 이름을 완벽하게 입력하였을 경우 SQL
Sql.BeginUpdate;
Sql.clear;
Sql.add('select no2,no1,cont');
Sql.add('from result');
Sql.add('where no2 like :no2');
Sql.EndUpdate;
ParamByName('no2').AsString := Mgiho.Text + '%';
Open;
if RecordCount = 0 then // 찾아온 자료가 없으면 신규
begin
messagedlg('신규입니다!',mtinformation,[mbok],0);
Mgu.setfocus;
Lbiname.visible:=false;
Exit;
end else
begin
Key := #0;
LBIName.Items.BeginUpdate;
LBIName.Items.Clear; //이름 리스트박스 초기화
while not EOF do // 이름 검색 리스트박스에 데이터 넣기
begin
m_giho := FindField('no2').AsString;
for i := 1 to 10 - Length(m_giho) do
m_giho := m_giho + ' '; //나머지는 공백으로 처리
m_gubun:=findfield('no1').AsString;
if findfield('no1').AsString='1' then
begin
m_gubun:='교수';
end;
if findfield('no1').AsString='2' then
begin
m_gubun:='학생';
end;
if findfield('no1').AsString='3' then
begin
m_gubun:='조교';
end;
LBIName.Items.Add(m_giho +' '+ m_gubun+ ' '+ FindField('cont').AsString);
Next;
end;
LBIName.Items.EndUpdate;
LBIName.ItemIndex := 0;
if LBIName.Items.Count = 1 then
begin
SendMessage(LBIName.Handle, WM_CHAR, 13, 0);
end else
begin
LbiName.Height := 200;
LbiName.BringToFront;
LbiName.Visible := True;
LbiName.SetFocus;
end;
end;
end;
end;
if key=#27 then
begin
Lbiname.visible:=false;
screenclear;
end;
end;
|