일단 의도는 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.
:
:
: 소스를 짯는데;
: 한칸씩 내려가지를 않습니다 ㅠㅠ
: 뭐가 잘못된건지좀 가르쳐 주세요 ㅠㅠ
|