소스를 분석하는게 힘듭니다..도와주세요...
그리고 틱이님// 감사 또 감사....
function Check_ValidDate(AYear,Amonth,Aday :integer) :boolean ;
begin
Result := not( (AMonth < 1) or (AMonth > 12) or (AYear < 1900)
or (Aday < 1) or (Aday > DaysPerMonth(AYear,AMonth)) );
end;
function Check_Date(s :string) : string;
var
i, j : shortint ;
syear,smonth,sday : string ;
ayear,amonth,aday : integer ;
begin
while Pos('-',s) > 0 do
system.delete(s,Pos('-',s),1);
while Pos('',s) > 0 do
system.delete(s,Pos('',s),1);
syear := ''; smonth :=''; sday :='';
for i := 1 to Length(s) do
if (i > 0) and (i < 5) and (s[i] <> ' ') then
syear := syear + s[i] else
if (i = 5) or (i = 6) and (s[i] <> ' ') then
smonth := smonth + s[i] else
if (i = 7) or (i = 8) and (s[i] <> ' ') then
sday := sday + s[i] ;
if (syear = ' ') or (smonth = ' ') or (sday = ' ') then
begin
Result := '0';
exit;
end;
ayear := strtoint(syear);
amonth := strtoint(smonth);
aday := strtoint(sday);
if not Check_ValidDate(ayear,amonth,aday) then
begin
Result := '0';
exit;
end;
if (amonth < 10) and (Length(smonth) < 2) then
smonth := '0' + smonth;
if (aday < 10) and (Length(sday) < 2) then
sday := '0' + sday;
Result := syear + smonth + sday;
end;
procedure TForm1.bitbtn1Click(Sender: TObject);
begin
caption := check_date(maskedit1.text);
end;
end.
이 coding은 maskedit에 입력된 날짜가 올바른 날짜인지 잘못된 날짜인지를
체크하는 coding입니다.
체크하는 방법은 maskedit에서 년,월,일 의 구분이 '-'로 구분되어있는데
이 구분자를 삭제한후 년, 월, 일 을 각각 다른 변수에 옮기고
년이 1900년 이상인지, 자리수가 4자리 맞는지를 체크하며
월이 1월에서 12월 사이인지를 체크하고
일은 연도별로, 월별로 들어가는 각각의 일자가 틀리므로 DaysPerMonth 프로로시져를
사용하여 날짜가 정확히 입력되는가를 체크해서
maskedit에 들어가는 결과값이 제대로 맞는 날짜인지를 체크하는 coding이라는 거죠..
이 코딩에 있어서 최종 결과값은(즉 caption에 들어가는 값) maskedit에서 구분자('-')를
제외한 값이 caption에 들어가겠네요...(예를들면 2001-07-26 ==> 20010726 이렇게요..)
사실 이런 coding은 불필요한 coding인거 같습니다..(저도 초보지만...)
아주 간단하게 coding해도 될것을 너무 복잡하게 짜여진 coding같네요..
부분적으로 설명 드리자면
function Check_ValidDate(AYear,Amonth,Aday :integer) :boolean ;
begin
Result := not( (AMonth < 1) or (AMonth > 12) or (AYear < 1900)
or (Aday < 1) or (Aday > DaysPerMonth(AYear,AMonth)) );
end;
--> 이 부분은 연, 월, 일이 제대로 입력되었는지를 체크하여 y,n의 결과값을 결정짓구요..
function Check_Date(s :string) : string;
var
i, j : shortint ;
syear,smonth,sday : string ;
ayear,amonth,aday : integer ;
begin
while Pos('-',s) > 0 do
system.delete(s,Pos('-',s),1);
while Pos('',s) > 0 do
system.delete(s,Pos('',s),1);
syear := ''; smonth :=''; sday :='';
for i := 1 to Length(s) do
if (i > 0) and (i < 5) and (s[i] <> ' ') then
syear := syear + s[i] else
if (i = 5) or (i = 6) and (s[i] <> ' ') then
smonth := smonth + s[i] else
if (i = 7) or (i = 8) and (s[i] <> ' ') then
sday := sday + s[i] ;
if (syear = ' ') or (smonth = ' ') or (sday = ' ') then
begin
Result := '0';
exit;
end;
ayear := strtoint(syear);
amonth := strtoint(smonth);
aday := strtoint(sday);
if not Check_ValidDate(ayear,amonth,aday) then
begin
Result := '0';
exit;
end;
if (amonth < 10) and (Length(smonth) < 2) then
smonth := '0' + smonth;
if (aday < 10) and (Length(sday) < 2) then
sday := '0' + sday;
Result := syear + smonth + sday;
end;
--> 이 부분은 위에서 maskedit에 입력받은 값에서 구분자를('-')를 제외시키고 나온 값을
(다시말해서 '-'값을 찾으면 그 전까지의 값(실제값)을 변수에 넣고 '-'까지 삭제합니다..
즉 이런식으로 년,월, 일 을 또 다른 변수에 넣는 방법을 사용했네요...)
결과값으로 출력시키는 부분입니다.
물론 월,일 이 1자리라면 앞에 0을 붙여 2자리로 만들어주는 기능이 포함되어 있죠..
procedure TForm1.bitbtn1Click(Sender: TObject);
begin
caption := check_date(maskedit1.text);
end;
--> 이부분은 위에서의 결과값을 ,caption에 뿌려주는 기능이구요...
(다시 말씀드려서 2001-07-26 이 20000726으로 변화되어 나타내어주는 부분입니다.)
설명이 너무 복잡했나요?
제 나름대로 간단하게 설명드린다는것이 글이 많이 길어진거 같습니다.
그럼...
귀염둥이 wrote:
> 소스를 분석하는게 힘듭니다..도와주세요...
> 그리고 틱이님// 감사 또 감사....
> function Check_ValidDate(AYear,Amonth,Aday :integer) :boolean ;
> begin
> Result := not( (AMonth < 1) or (AMonth > 12) or (AYear < 1900)
> or (Aday < 1) or (Aday > DaysPerMonth(AYear,AMonth)) );
> end;
>
> function Check_Date(s :string) : string;
> var
> i, j : shortint ;
> syear,smonth,sday : string ;
> ayear,amonth,aday : integer ;
> begin
> while Pos('-',s) > 0 do
> system.delete(s,Pos('-',s),1);
> while Pos('',s) > 0 do
> system.delete(s,Pos('',s),1);
> syear := ''; smonth :=''; sday :='';
>
> for i := 1 to Length(s) do
> if (i > 0) and (i < 5) and (s[i] <> ' ') then
> syear := syear + s[i] else
> if (i = 5) or (i = 6) and (s[i] <> ' ') then
> smonth := smonth + s[i] else
> if (i = 7) or (i = 8) and (s[i] <> ' ') then
> sday := sday + s[i] ;
>
> if (syear = ' ') or (smonth = ' ') or (sday = ' ') then
> begin
> Result := '0';
> exit;
> end;
> ayear := strtoint(syear);
> amonth := strtoint(smonth);
> aday := strtoint(sday);
>
> if not Check_ValidDate(ayear,amonth,aday) then
> begin
> Result := '0';
> exit;
> end;
> if (amonth < 10) and (Length(smonth) < 2) then
> smonth := '0' + smonth;
> if (aday < 10) and (Length(sday) < 2) then
> sday := '0' + sday;
> Result := syear + smonth + sday;
> end;
> procedure TForm1.bitbtn1Click(Sender: TObject);
> begin
> caption := check_date(maskedit1.text);
> end;
>
>
>
>
> end.
>
>