다음 소스는 info2.txt 라는 파일을 불러와서 , 로 구분되어있는 문자열들을 StringGrid로 옮기는 작업을 하는것입니다.
보시다 시피 폼이 만들어질때 파일을 가져와서(파일 내용은 수검번호,이름,주민번호,학년,반으로 , 로 구분되어져 있습니다.) 일단 파일이 있는지 확인하고 ,를 찾아서 각 변수에 복사, 삭제를 반복하는 형식으로 되어있습니다. 아 힘들다.ㅜ.ㅡ
procedure TForm1.FormCreate(Sender: TObject);
var
temp, st, files, bun, name, jumin, school, hak, ban:string;
n, p:Integer;
fh:TextFile;
begin
n:=1;
files:='info2.txt';
StringGrid1.Cells[0,0]:='수검번호';
StringGrid1.Cells[1,0]:='이름';
StringGrid1.Cells[2,0]:='주민번호';
StringGrid1.Cells[3,0]:='학년';
StringGrid1.Cells[4,0]:='반';
if not FileExists(files) then
begin
ShowMessage(files+'파일이 없습니다.');
Exit;
end;
AssignFile(fh,files);
Reset(fh);
while not Eof(fh) do
begin
ReadLn(fh,temp);
p:=Pos(',',temp);
bun:=Copy(temp,1,p-1);
Delete(temp,1,p);
p:=Pos(',',temp);
name:=Copy(temp,1,p-1);
Delete(temp,1,p);
p:=Pos(',',temp);
jumin:=Copy(temp,1,p-1);
Delete(temp,1,p);
p:=Pos(',',temp);
school:=Copy(temp,1,p-1);
Delete(temp,1,p);
if ComboBox1.Items.IndexOf(school)= -1 then
ComboBox1.Items.Add(school);
p:=Pos(',',temp);
hak:=Copy(temp,1,p-1);
Delete(temp,1,p);
ban:=temp;
StringGrid1.Cells[0,n]:=bun;
StringGrid1.Cells[1,n]:=name;
StringGrid1.Cells[2,n]:=jumin;
StringGrid1.Cells[3,n]:=hak;
StringGrid1.Cells[4,n]:=ban;
StringGrid1.RowCount:= n+1;
Inc(n);
end;
Caption:='건수 : '+IntToStr(n-1);
end;
'델파이' 카테고리의 다른 글
StringGrid 에 있는 데이타 엑셀로 옮기기 (매크로 사용? 이라고 해야하나?) (0) | 2007.11.24 |
---|---|
델파이 5에서 잘되던 VarArrayOf 와 VarArrayCreate 를 델파이 7에서 이용법과 문법 (0) | 2007.11.23 |
델파이 EditBox 특정 키 입력 막기 예제 (0) | 2007.11.18 |