코딩이 어디가 잘못됐는지 모르겠어여,
배운지 한 열흘 됐는데, 그냥 포기하고 싶군여, 포기하더래두 알고 포기해야져.
제가 코딩한건데 뭐가 잘못됐는지,,,
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=1 then Edit1.Text := FormatDateTime( 'YYYY.MM', IncMonth(Now,-2) )
+ ' ~ ' + FormatDateTime( 'YYYY.MM', IncMonth(Now,-1) );
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=2 then Edit2.Text := FormatDateTime( 'YYYY.MM', IncMonth(Now,-4) )
+ ' ~ ' + FormatDateTime( 'YYYY.MM', IncMonth(Now,-3) );
end;
end.
> 코딩이 어디가 잘못됐는지 모르겠어여,
> 배운지 한 열흘 됐는데, 그냥 포기하고 싶군여, 포기하더래두 알고 포기해야져.
> 제가 코딩한건데 뭐가 잘못됐는지,,,
>
> unit Unit1;
>
> interface
>
> uses
> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
> StdCtrls;
>
> type
> TForm1 = class(TForm)
> Edit1: TEdit;
> Edit2: TEdit;
> procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
> procedure Edit1Change(Sender: TObject);
> procedure Edit2Change(Sender: TObject);
>
> private
> { Private declarations }
> public
> { Public declarations }
> end;
>
> var
> Form1: TForm1;
>
> implementation
>
> {$R *.DFM}
>
> procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
> begin
> if key=1 then Edit1.Text := FormatDateTime( 'YYYY.MM', IncMonth(Now,-2) )
> + ' ~ ' + FormatDateTime( 'YYYY.MM', IncMonth(Now,-1) );
>
> end;
>
> procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
> begin
> if key=2 then Edit2.Text := FormatDateTime( 'YYYY.MM', IncMonth(Now,-4) )
> + ' ~ ' + FormatDateTime( 'YYYY.MM', IncMonth(Now,-3) );
> end;
>
> end.
>
>
>
edit1에 '1'을 넣었을때겠죠?
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then //enter key
begin
if Edit1.Text = '1' then
Edit1.Text := FormatDateTime( 'YYYY.MM', IncMonth(Now,-2) )
+ ' ~ ' + FormatDateTime( 'YYYY.MM', IncMonth(Now,-1) );
end;
end;
그리구요, 먼저 form의 KeyPreview를 True로 설정하시야합니다.
천천히 즐겁게 코딩하세요...