home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / D1 / CALCBOX.ZIP / DEMO / DRAGDROP.PAS < prev    next >
Pascal/Delphi Source File  |  1995-12-30  |  3KB  |  124 lines

  1. unit Dragdrop;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Cvgcalc, Buttons;
  8.  
  9. type
  10.   TForm3 = class(TForm)
  11.     BitBtn1: TBitBtn;
  12.     Label1: TLabel;
  13.     CalculatorBox1: TCalculatorBox;
  14.     CalculatorBox2: TCalculatorBox;
  15.     CalculatorBox3: TCalculatorBox;
  16.     Edit1: TEdit;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     Label4: TLabel;
  20.     Label5: TLabel;
  21.     Label6: TLabel;
  22.     Shape1: TShape;
  23.     Shape2: TShape;
  24.     Shape3: TShape;
  25.     Shape4: TShape;
  26.     Shape5: TShape;
  27.     Shape6: TShape;
  28.     Shape7: TShape;
  29.     Image1: TImage;
  30.     Image2: TImage;
  31.     Image3: TImage;
  32.     Image4: TImage;
  33.     Label7: TLabel;
  34.     Shape8: TShape;
  35.     Shape9: TShape;
  36.     Shape10: TShape;
  37.     Image5: TImage;
  38.    
  39.     procedure CalculatorBox2DragOver(Sender, Source: TObject; X,
  40.       Y: Integer; State: TDragState; var Accept: Boolean);
  41.     procedure CalculatorBox3DragOver(Sender, Source: TObject; X,
  42.       Y: Integer; State: TDragState; var Accept: Boolean);
  43.     procedure CalculatorBox2DragDrop(Sender, Source: TObject; X,
  44.       Y: Integer);
  45.     procedure Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
  46.     procedure CalculatorBox3DragDrop(Sender, Source: TObject; X,
  47.       Y: Integer);
  48.     procedure Edit1Change(Sender: TObject);
  49.     procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  50.   private
  51.     { Private declarations }
  52.   public
  53.     { Public declarations }
  54.   end;
  55.  
  56. var
  57.   Form3: TForm3;
  58.  
  59. implementation
  60.  
  61. {$R *.DFM}
  62.  
  63.  
  64.  
  65. procedure TForm3.CalculatorBox2DragOver(Sender, Source: TObject; X,
  66.   Y: Integer; State: TDragState; var Accept: Boolean);
  67. begin
  68.   Accept := Source is TCalculatorBox;
  69. end;
  70.  
  71. procedure TForm3.CalculatorBox3DragOver(Sender, Source: TObject; X,
  72.   Y: Integer; State: TDragState; var Accept: Boolean);
  73. begin
  74.   Accept := Source is TEdit;
  75. end;
  76.  
  77. procedure TForm3.CalculatorBox2DragDrop(Sender, Source: TObject; X,
  78.   Y: Integer);
  79. begin
  80. CalculatorBox2.displaytext:= (Source as TCalculatorBox).Text;
  81. end;
  82.  
  83. procedure TForm3.Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
  84. begin
  85. Edit1.text:= (Source as TCalculatorBox).Text;
  86. end;
  87.  
  88. procedure TForm3.CalculatorBox3DragDrop(Sender, Source: TObject; X,
  89.   Y: Integer);
  90. begin
  91.    CalculatorBox3.displaytext:= (Source as TEdit).Text;
  92. end;
  93.  
  94. procedure TForm3.Edit1Change(Sender: TObject);
  95. var
  96.   mystring: string;
  97.   holdit : string[1];
  98.   lnth: integer;
  99. begin
  100. mystring:=edit1.text;
  101. lnth := length(mystring);
  102. if lnth>0 then
  103.  begin
  104.  holdit := mystring[lnth];
  105.    if strToint(holdit) >  9 then
  106.     if strToint(holdit) < 0  then
  107.     edit1.text:=copy( mystring,1,lnth-1);
  108.  end;
  109. end;
  110.  
  111.  
  112.  
  113.  
  114. procedure TForm3.Edit1KeyPress(Sender: TObject; var Key: Char);
  115. begin
  116. if ( (key < '0') OR (key > '9') ) AND ( key <> #8 ) then
  117.   begin
  118.     MessageBeep(0);
  119.     Key := #0;
  120.   end;
  121. end;
  122.  
  123. end.
  124.