delphi对数据表的列求和代码问题

unit Utotal;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Mask, DBCtrls, Buttons, DB, DBTables,
ComCtrls, Spin, DBActns, ActnList;

type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
EditName: TEdit;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Table1Salory: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
SpeedButton6: TSpeedButton;
Table1: TTable;
DataSource1: TDataSource;
SpinEdit1: TSpinEdit;
ActionList1: TActionList;
DataSetFirst1: TDataSetFirst;
DataSetNext1: TDataSetNext;
DataSetPrior1: TDataSetPrior;
DataSetLast1: TDataSetLast;
procedure FormCreate(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.IndexFieldNames :='LastName';
table1.First ;
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
Table1.FindNearest([EditName.Text] );
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
var
bookmark:TBookmark;
Total:real;
begin
bookmark:=TABLE1.GetBookmark ;
TABLE1.DisableControls ;
Total:=0;
try
Table1.First ;
while not Table1.Eof do
begin
Table1.Edit ;
Table1Salary.value:=round(Table1salary.value*spinedit1.Value )/100;
//这句的Table1Salary.value出现问题 :Undeclared identifier:Table1Salary

total:=total+table1Salary.value;
//将雇员工资累加
Table1.Next ;
end;
finally
Table1.Gotobookmark(bookmark);
Table1.freebookmark(bookmark);
Table1.enablecontrols;
end;
MessageDlg('调节后的工资总数为'+Format('%m',[total]),mtInformation,[mbOK],0);
end;

end.
大侠们:在哪里声明标识符Table1Salary?怎样声明?
cpplyy 的回答不对。table1下根本就没有salary这一项。
注:上述代码是来自《delphi6.0网络及数据库时尚编程百例》一书,原书附带光盘已丢失。

第1个回答  2008-10-22
//这句的Table1Salary.value出现问题 :Undeclared identifier:Table1Salary

改为Table1.Salary.value
=====================================================
问题补充:cpplyy 的回答不对。table1下根本就没有salary这一项。
注:上述代码是来自《delphi6.0网络及数据库时尚编程百例》一书,原书附带光盘已丢失。

那Salary就是表的字段了?
Table1Salary.value改为
Table1.FieldValues['Salary']

时尚编程 ,囧。本回答被提问者采纳
第2个回答  2008-10-22
两个办法:
(1)Table1.getfieldbyname('salary').value;

(2)双击Table1控件,在弹出的Filed窗口中添加字段(可以选择的),其中包Salary字段,添加完成后,pas单元中会增加一个table1salary的变量,你就可以直接用了
相似回答