Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[12644] Re:이 소스에 문제점좀 찾아주세요 ㅠ
seg [] 1574 읽음    2009-04-21 19:01
일단 의도는 button 을 누를 때마다 editbox 등에 입력한 정보가 stringgrid 에 한 줄씩 채워지도록 하려는 의도로 보입니다.

문제는 cnt 를  button1click procedure 안에서 계속 1 로 reset 하기 때문에, 첫 번째 줄만 계속 바뀔 것입니다.

따라서...

unit Unit1;
uses....
type
  TForm1 = class(TForm)
    .......................

  private
     cnt : integer;   //여기서 정의한 다음,

  end;


implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
   StringGrid1.Cells[0,0]:='코드' ;
    ..........................
  StringGrid1.Cells[9,0]:='번호' ;
 
  cnt := 1;    // form 이 처음 생성될 때 1로 set 합니다.
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    // cnt : integer;          // 여기서 cnt 를 다시 정의하면 안됩니다.
        s : String;
begin
    // cnt := 1;                // 여기서 reset 해도 안됩니다.

    s:=' ';
       ....................
    inc (cnt);    //  여기서 버튼을 누를 때마다  cnt 의 값이 1씩 더해져서 unit 내에서 전역변수에  저장됩니다.
end;

이렇게 고쳐서 한 번 해 보시길..  다만, 프로그램 한 번 종료했다가 다시 시작하면 처음부터 다시 합니다.
따라서 한 번 입력한 내용을 저장했다가 다시 loading 하는 문제가 다음 단계이겠네요.



후아힝 님이 쓰신 글 :
: procedure TForm1.FormCreate(Sender: TObject);
: begin
:
: StringGrid1.Cells[0,0]:='코드' ;
: StringGrid1.Cells[1,0]:='학과' ;
: StringGrid1.Cells[2,0]:='학번' ;
: StringGrid1.Cells[3,0]:='이름' ;
: StringGrid1.Cells[4,0]:='국어점수';
: StringGrid1.Cells[5,0]:='영어점수';
: StringGrid1.Cells[6,0]:='점수합계';
: StringGrid1.Cells[7,0]:='점수평균';
: StringGrid1.Cells[8,0]:='성별' ;
: StringGrid1.Cells[9,0]:='번호' ;
: end;
:
: procedure TForm1.Button1Click(Sender: TObject);
: var
: cnt : integer;
: s : String;
: begin
: cnt := 1;
: s:=' ';
:
:
:
: if ComboBox1.Text = '전자공학과' then
: StringGrid1.Cells[0, cnt] := '01';
: if ComboBox1.Text = '전기공학과' then
: StringGrid1.Cells[0, cnt] := '02';
: if ComboBox1.Text = '컴퓨터공학과' then
: StringGrid1.Cells[0, cnt] := '03';
:
: StringGrid1.Cells[1, cnt] := ComboBox1.Text;
:
: StringGrid1.Cells[2, cnt] := Edit1.Text;
: StringGrid1.Cells[3, cnt] := Edit2.Text;
:
: if RadioGroup1.ItemIndex = 0 then
: StringGrid1.Cells[4, cnt] := '남자';
: if RadioGroup1.ItemIndex = 1 then
: StringGrid1.Cells[4, cnt] := '여자';
:
: StringGrid1.Cells[5, cnt] := Edit3.Text;
: StringGrid1.Cells[6, cnt] := Edit4.Text;
:
: StringGrid1.Cells[7, cnt] := intTostr(StrToint(Edit3.Text)+(StrToint(Edit4.Text)));
: StringGrid1.Cells[8, cnt] := FloatTostr(StrToint(StringGrid1.Cells[7, cnt]) / 2 );
:
:
: if CheckBox1.Checked = true then
: S := S + '1'
: else
: S := S + '0';
: if CheckBox2.Checked = true then
: S := S + '1'
: else
: S := S + '0';
: if CheckBox3.Checked = true then
: S := S + '1'
: else
: S := S + '0';
: if CheckBox4.Checked = true then
: S := S + '1'
: else
: S := S + '0';
: if CheckBox5.Checked = true then
: S := S + '1'
: else
: S := S + '0';
:
: StringGrid1.Cells[9, cnt] := s;
: inc(cnt);
:
:
: end;
:
: end.
:
:
: 소스를 짯는데;
: 한칸씩 내려가지를 않습니다 ㅠㅠ
: 뭐가 잘못된건지좀 가르쳐 주세요 ㅠㅠ

+ -

관련 글 리스트
12630 이 소스에 문제점좀 찾아주세요 ㅠ 후아힝 1398 2009/04/20
12644     Re:이 소스에 문제점좀 찾아주세요 ㅠ seg 1574 2009/04/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.