unit ImeiEdit; {$R ImeiEdit.res} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Mask; type TImeiEdit = class(TPanel) private { Private declarations } FBitmap:TBitmap; protected { Protected declarations } fImeiList : TStringList; fCombo : TComboBox; fEdit : TMaskEdit; fButton1 : TBitBtn; fButton2 : TBitBtn; fComboRate : single; fOnButton1Click : TNotifyEvent; fOnButton2Click : TNotifyEvent; fTypeList : Boolean; fbutton2visible:boolean; procedure resize; override; procedure SetComboRate(Value:single); procedure myclick1(sender:tobject); procedure myclick2(sender:tobject); procedure SetTypeList(Value:Boolean); procedure setimei1(value:string); function getimei1:string; procedure setimei2(value:string); function getimei2:string; procedure SetBothEnabled( Value : Boolean ); Function GetBothEnabled : boolean; procedure SetButton2Visible( Value : Boolean ); public { Public declarations } constructor Create(Owner:TComponent); override; destructor Destroy; override; procedure InitTypes(Name,Imei:TStringList); Property Imei1:string read getimei1 write setimei1; Property Imei2:string read getimei2 write setimei2; published { Published declarations } Property ComboRate:single read fComboRate write SetComboRate; property OnButton1Click: TNotifyEvent read FOnButton1Click write FOnButton1Click; property OnButton2Click: TNotifyEvent read FOnButton2Click write FOnButton2Click; Property TypeList:boolean read FTypeList write SetTypeList; property BothEnabled:boolean read GetBothEnabled write SetBothEnabled; property Button2Visible:boolean read fButton2Visible write SetButton2Visible; end; procedure Register; implementation constructor TImeiEdit.Create(Owner:TComponent); begin Inherited Create(Owner); fCombo:=TComboBox.create(self); fCombo.Parent:=self; fCombo.Style:=CsDropDownList; fcombo.hint:='Készülék tipus kiválasztás'; fcombo.taborder:=0; fEdit:=TMaskEdit.create(self); fEdit.parent:=self; fEdit.editmask:='00\-000000\-0;0; '; fEdit.hint:='IMEI 7-9. számjegy'; fedit.taborder:=1; fButton2:=TBitBtn.create(self); fButton2.parent:=self; fButton2.onclick:=myclick2; fbutton2.hint:='IMEI jóváhagyása'; fbutton2.taborder:=3; FBitMap:=TBitMap.Create; FBitMap.Handle := LoadBitmap(Hinstance,'Refresh'); FButton2.Glyph:=FBitMap; fButton1:=TBitBtn.create(self); fButton1.parent:=self; fButton1.onclick:=myclick1; fbutton1.hint:='Készülék kiválasztó ablak'; fbutton2.taborder:=2; FBitMap.Handle := LoadBitmap(Hinstance,'Mobile'); FButton1.Glyph:=FBitMap; FBitMap.free; fbutton2visible:=true; fTypeList:=True; fComboRate:=0.5; Height:=24; BevelOuter:=bvNone; fImeiList:=TStringList.Create; showhint:=true; resize; end; destructor TImeiEdit.Destroy; begin fImeiList.Free; fCombo.free; fedit.free; fButton1.free; fButton2.free; inherited Destroy; end; procedure TImeiEdit.MyClick1(Sender:TObject); begin if assigned(FOnButton1Click) then FOnButton1Click(sender); end; procedure TImeiEdit.MyClick2(Sender:TObject); begin if assigned(FOnButton2Click) then FOnButton2Click(sender); end; procedure TImeiEdit.setimei1(value:string); var i:integer; begin {write imei 1-6} if ftypelist then begin fcombo.text:=''; fcombo.itemindex:=-1; for i:=0 to fimeilist.count-1 do if fimeilist[i]=copy(value,1,6) then fcombo.itemindex:=i; end else begin fedit.text:=copy(value,1,6)+copy(fedit.text,7,9); end; end; function TImeiEdit.getimei1:string; begin {read imei 1-6} if ftypelist then begin if fcombo.itemindex=-1 then result:=' '+fedit.text else result:=fimeilist[fcombo.itemindex]; end else result:=copy(fedit.text,1,6); end; procedure TImeiEdit.setimei2(value:string); var i:integer; begin {write imei 7-15} if ftypelist then begin fedit.text:=copy(value,1,9); end else begin fedit.text:=copy(fedit.text,1,6)+copy(value,1,9); end; end; function TImeiEdit.getimei2:string; begin {read imei 7-15} if ftypelist then begin result:=fedit.text; end else result:=copy(fedit.text,7,9); end; procedure TImeiEdit.SetBothEnabled( Value : Boolean ); begin fcombo.enabled:=value; fedit.enabled:=value; fbutton1.Enabled := Value; fbutton2.Enabled := Value; Enabled:=Value; end; Function TImeiEdit.GetBothEnabled : boolean; begin Result := Enabled; end; procedure TImeiEdit.SetButton2Visible( Value : Boolean ); begin if fbutton2visible<>value then begin fbutton2visible:=value; fbutton2.visible:=value; resize; end; end; procedure TImeiEdit.InitTypes(Name,Imei:TStringList); begin fcombo.items.clear; fcombo.items.assign(name); fImeiList.assign(Imei); end; procedure TImeiEdit.SetComboRate(Value:single); begin if Value>=0 then FComboRate:=Value; Resize; end; procedure TImeiEdit.SetTypeList(Value:Boolean); var i:integer; s:string; begin if typelist<>value then begin if value then s:=fedit.text else begin if fcombo.itemindex=-1 then s:=' '+fedit.text else s:=fimeilist[fcombo.itemindex]+fedit.text; end; fedit.text:=''; fcombo.itemindex:=-1; fTypeList:=Value; if fTypeList then fEdit.editmask:='00\-000000\-0;0; ' else fEdit.editmask:='000000\-00\-000000\-0;0; '; if value then begin fedit.text:=copy(s,7,9); fcombo.text:=''; for i:=0 to fimeilist.count-1 do if fimeilist[i]=copy(s,1,6) then fcombo.itemindex:=i; end else fedit.text:=copy(s,1,15); Resize; end; end; procedure TImeiEdit.Resize; var reltop,buttonswidth:integer; begin reltop:=round((height-fcombo.height)/2); if fbutton2visible then buttonswidth:=height*2 else buttonswidth:=height; if fTypeList then begin fcombo.top:=reltop; fcombo.left:=0; fcombo.width:=round((width-buttonswidth)*comborate); fedit.top:=reltop; fedit.left:=fcombo.width-4; fedit.width:=width-buttonswidth-fcombo.width; fedit.height:=fcombo.height; fbutton1.top:=0; fbutton1.left:=fcombo.width+fedit.width; fbutton1.width:=width-fcombo.width-fedit.width+height-buttonswidth; fbutton1.height:=height; if fbutton2visible then begin fbutton2.top:=0; fbutton2.left:=fcombo.width+fedit.width+fButton1.Width; fbutton2.width:=width-fcombo.width-fedit.width-fButton1.Width; fbutton2.height:=height; end; end else begin fcombo.top:=reltop; fcombo.left:=0; fcombo.width:=round((width-buttonswidth)*comborate); fedit.top:=reltop; fedit.left:=0; fedit.width:=width-buttonswidth-4; fedit.height:=fcombo.height; fbutton1.top:=0; fbutton1.left:=fedit.width+4; fbutton1.width:=width-fedit.width+height-buttonswidth-4; fbutton1.height:=height; if fbutton2visible then begin fbutton2.top:=0; fbutton2.left:=fedit.width+fButton1.Width+4; fbutton2.width:=width-fedit.width-fButton1.Width-4; fbutton2.height:=height; end; end; end; procedure Register; begin RegisterComponents('DPR', [TImeiEdit]); end; end.