델파이2007. 11. 23. 20:47
델파이 5에서 잘 되던 VarArrayOf와 VarArrayCreate가 안되면..
uses 절에 Variants 를 추가해줘야 쓸수 있다.

var
  data :Variant;
begin
  data:=VarArrayOf(배열에 들어갈 내용);
  //ex
  data:=VarArrayOf('번호','이름','점수');

  data:=VarArrayCreate([시작지점,생성할갯수],자료형); // 이거 되긴 하는데 시작지점과 생성갯수가 확실한지 모르겠다!! 저는 비기너니까*-_-* 누가 좀 알려주세요!! 도움말에는 The Bounds_size parameter is the index of the last value in the Bounds array. 이렇게 나와있습니다..(..) 번역 바랍니다... 쿨럭..
  //ex
  data:=VarArrayCreate([1,3],varVariant);
  //위와 같이 선언하고 data[1]:='번호'; data[2]:='이름'; data[3]:='점수'; 와 같이 사용할 수 있다.

다음엔 이 Variant 타입을 엑셀로 내보내는걸 복습하자!!
Posted by Mons
델파이2007. 11. 19. 23:52

다음 소스는 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;

Posted by Mons
델파이2007. 11. 18. 21:51

델파이 에서 EditBox 특정 키 입력을 막는 예제입니다.

  if not (Key in ['A'..'Z','a'..'z',#8,#32]) then
    Key := #0;

이 코드를 OnKeyPress 에 넣어주시면 되겠습니다.
보시다시피 들어온 Key의 값이 A 부터 Z, a 부터 z,
BackSpace(아스키 코드 8)키 스페이스 키(아스키 코드값 32)가 아니라면 키 입력을 막게끔 되겠습니다!

Posted by Mons