Q&A

  • currency edit 컴포넌트 초기화문제....(소스포함)
안녕하세요, 델파이를 열심히 공부중이지만 완전초보가 질문을 드리려고 합니다. 제가 어디서 currency edit component를 다운받아서 사용을 하려고 하는데 초기화가 되지않습니다. 예를 들어 10000을 쓰고 currency1.clear을 하면 보기에는 지워지는데 다시 2000을 쓰면 앞1000 이라는 숫자가 나오는군요 그러니까 10002000 이렇게 말이죠 제발 좀 부탁드리겠습니다. 좋은하루되세요.

unit CurrencyEdit;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls,

Forms, Dialogs, StdCtrls;



type



TCurrencyEdit = class(TCustomMemo)

private

FPoint : Boolean;

FNegative : Boolean;

FSign : Boolean;

FSignChar : char;

FValue : Extended;

FText : String;

FFormatText : string;

PeriodCheck : Boolean;

procedure SetValue(val:extended);

procedure SetPoint(BPoint:boolean);

procedure SetNegative(Nega:boolean);

procedure SetSign(Sign:Boolean);

procedure SetSignChar(signchar:char);



protected

procedure KeyPress(var Key:Char);override;

procedure KeyDown(var Key:Word; Shift: TShiftState);override;

procedure TextChange;



public

constructor Create(AOwner:TComponent); override;



published

property Alignment default taRightJustify;

property BorderStyle;

property Color;

property Ctl3D;

property CurrencyPoint:boolean read FPoint write Setpoint default False;

property CurrencyNegative:boolean read FNegative write SetNegative default False;

property CurrencySign:Boolean read FSign write SetSign default false;

property CurrencySignChar:char read FSignChar write SetSignChar;

property DragCursor;

property DragMode;

property Enabled;

property Font;

property HideSelection;

property MaxLength;

property ParentColor;

property ParentCtl3D;

property ParentFont;

property ParentShowHint;

property PopupMenu;

property ReadOnly;

property ShowHint;

property TabOrder;

property Value: Extended read FValue write SetValue;

property Visible;



property OnChange;

property OnClick;

property OnDblClick;

property OnDragDrop;

property OnDragOver;

property OnEndDrag;

property OnEnter;

property OnExit;

property OnKeyDown;

property OnKeyPress;

property OnKeyUp;

property OnMouseDown;

property OnMouseMove;

property OnMouseUp;



end;



procedure Register;



implementation



procedure Register;

begin

RegisterComponents('Additional', [TCurrencyEdit]);

end;



constructor TCurrencyEdit.Create(AOwner : TComponent);

begin

inherited Create(AOwner);

AutoSize := False;

Alignment := taRightJustify;

Width := 120;

Height := 24;

MaxLength := 12;



FValue := 0;

FText := '';

PeriodCheck := False;



end;



procedure TCurrencyEdit.KeyPress(var Key:char);

var

RangeCheck : Boolean;

begin



if FPoint then

RangeCheck := Key in ['0'..'9', '.', #8, #127]

else

RangeCheck := Key in ['0'..'9', #8, #127];



//음수허용경우

if (FNegative) and (FText='') then

if not RangeCheck then

RangeCheck := Key in ['-'];



if not RangeCheck then

key := #0

else

if (Length(FText) < MaxLength) or (Key=#8) then

begin

case Key of

'0'..'9' : FText:=FText+Key;

#8 : FText:=Copy(FText,1,Length(FText)-1);

'-' : FText:=FText+Key;

'.' : if not PeriodCheck then

FText:=FText+Key

end;

Key := #0;

TextChange;

end;

end;



procedure TCurrencyEdit.TextChange;

var

i : integer;

LengthCount : integer;

PointFlag : Boolean;

begin

FFormatText := '';

LengthCount := 0;

PointFlag := True;



if (FText='') or (FText='-') then //입력된값이 없을경우

begin

FValue:=0;

if FSign then

FFormatText := FSignChar;



if FText='-' then

FFormatText := FFormatText + '-';



end

else

begin

FValue := strtoFloat(FText);



for i := 1 to Length(FText) do // 소숫점제외한 자리수 계산

begin

if FText[i]='.' then PointFlag := False;

if PointFlag then LengthCount := LengthCount+1;

end;



if Not PointFlag then // 소숫점은 한번만 입력 허용

PeriodCheck := True

else

PeriodCheck := False;



if FText[1]='-' then //음수일때

begin

for i := 1 to LengthCount-1 do // 정수부분만 컴마 삽입

begin

FFormatText:=FText[LengthCount-i+1]+FFormatText;

if ((i mod 3) = 0) and (i<>LengthCount-1) then

FFormatText := ','+FFormatText;

end;

FFormatText:=FText[1]+FFormatText;

end

else //음수가 아닐때

for i := 1 to LengthCount do // 정수부분만 컴마 삽입

begin

FFormatText:=FText[LengthCount-i+1]+FFormatText;

if ((i mod 3) = 0) and (i<>LengthCount) then

FFormatText := ','+FFormatText;

end;



if FPoint then

if not PointFlag then // 소숫점이 있는경우

FFormatText:=FFormatText

+copy(FText,LengthCount+1,

Length(FText)-LengthCount);



if FSign then // 통화 기호가 있는경우

FFormatText := FSignChar+FFormatText;

end;



Text := FFormatText;



SelStart:=Length(Text);



end;



procedure TCurrencyEdit.KeyDown(var Key:Word; Shift: TShiftState);

var

RangeCheck : Boolean;

begin

RangeCheck := Key in [96..105, 8, 109, 189, 190, 110];

if not RangeCheck then

Key:=0;



SelStart:=Length(Text);

end;



procedure TCurrencyEdit.SetValue(val:Extended);

begin

Fvalue := val;

FText := floattostr(val);

TextChange;

end;



procedure TCurrencyEdit.SetPoint(BPoint : boolean);

begin

FPoint := BPoint;

TextChange;

end;



procedure TCurrencyEdit.SetNegative(Nega:Boolean);

begin

FNegative := Nega;

end;



procedure TCurrencyEdit.SetSign(sign:Boolean);

begin

FSign := Sign;

TextChange;

end;



procedure TCurrencyEdit.SetSignChar(SignChar:Char);

begin

FSignChar := signchar;

TextChange;

end;



end.

0  COMMENTS