我做了:
DECLARE @x int, @y int, @x1 int, @y1 int, @x2 int, @y2 int
DECLARE @atb2 float, @atp_dot_atb float
DECLARE @t float
--SELECT @x=0, @y=0
--SELECT @x1=1, @y1=10, @x2=1, @y2=-10
SELECT @x=2, @y=2
SELECT @x1=-1, @y1=2, @x2=3, @y2=0
SELECT @atb2 = SQUARE(@x2-@x1) + SQUARE(@y2-@y1) -- Basically finding the squared magnitude of a_to_b
SELECT @atp_dot_atb = (@x-@x1)*(@x2-@x1) + (@y-@y1)*(@y2-@y1) -- The dot product of a_to_p and a_to_b
SELECT @t = @atp_dot_atb / @atb2 -- The normalized "distance" from a to your closest point
SELECT @x1 + (@x2-@x1)*@t, @y1 + (@y2-@y1)*@t --Add the distance to A, moving towards B
它可以工作,但问题是当我点击按钮到达最后一条记录时,按钮没有被禁用,就像在procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
DataTable.qOrders.Next;
end;
中一样。
如何TDBNavigator
禁用并自动启用TSpeedButton
?
答案 0 :(得分:7)
将TActionList
放到您的表单上,然后将标准数据集操作添加到其中。将这些操作连接到数据集,并将速度按钮连接到相应的操作。这些标准操作将根据当前数据集状态处理启用状态。
答案 1 :(得分:1)
这是一个简单的解决方案,对我来说非常合适。
我有一个表单(frmMain),数据集(dsWork),数据源(srcWork),网格和两个速度按钮(btnNext和btnPrior)。重要的部分是TDataSource的“OnDataChange”事件。这是源代码:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBTables, StdCtrls, ExtCtrls;
type
TfrmMain = class(TForm)
btnNext: TButton;
srcWork: TDataSource;
dsWork: TTable;
btnPrior: TButton;
grdWork: TDBGrid;
procedure btnNextClick(Sender: TObject);
procedure btnPriorClick(Sender: TObject);
procedure srcWorkDataChange(Sender: TObject; Field: TField);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.btnNextClick(Sender: TObject);
begin
if not dsWork.Eof then dsWork.Next;
end;
procedure TfrmMain.btnPriorClick(Sender: TObject);
begin
if not dsWork.Bof then dsWork.Prior;
end;
procedure TfrmMain.srcWorkDataChange(Sender: TObject; Field: TField);
begin
btnNext.Enabled := not dsWork.Eof;
btnPrior.Enabled := not dsWork.Bof;
end;
end.