回 帖 发 新 帖 刷新版面

主题:这个程序错在哪??

在下照书里面copy了这段程序到机子上试,主要是通过4个按钮修改数据库表某字段的大小写,没通过,检查了N久不知错在哪,请各路高手帮看看错在哪,感激不尽!!!
源码是:
unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, StdCtrls;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Table1: TTable;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Table1CustNo: TFloatField;
    Table1Company: TStringField;
    Table1Addr1: TStringField;
    Table1Addr2: TStringField;
    Table1City: TStringField;
    Table1State: TStringField;
    Table1Zip: TStringField;
    Table1Country: TStringField;
    Table1Phone: TStringField;
    Table1FAX: TStringField;
    Table1TaxRate: TFloatField;
    Table1Contact: TStringField;
    Table1LastInvoiceDate: TDateTimeField;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function IsUpper(var ch: char): boolean;
    procedure ForceCase(var TargetField:AnsiString;ToUpper: boolean);
  end;

var
  Form1: TForm1;

implementation
var
  Upper,Mixed: boolean;
{$R *.dfm}
function TForm1.IsUpper(var ch: char): boolean;
begin
  if ( (ch>='A')or(ch <= 'Z')) then
    Result := true
  else
    Result := false;
end;
procedure TForm1.ForceCase(var TargetField:AnsiString;ToUpper: boolean);
var
WorkBuffer: String;
i: Integer;
begin
Table1.DisableControls;
try
Table1.First; //将记录指针移到第一条记录处
while not EOF do
begin
WorkBuffer:=(AnsiString)(FieldByName(TargetField));
if ToUpper then
begin
for i:=0 to strlen(WorkBuffer)-1 do
WorkBuffer[i] := UpCase(WorkBuffer[i]);
end
else
begin
for i := 0 to strlen(WorkBuffer) - 1 do
if IsUpper(WorkBuffer[i]) then
WorkBuffer[i]:=(Ansichar)(ord(WorkBuffer[i]) + 32);
WorkBuffer[1]:=UpCase(WorkBuffer[1]);
end;
Table1.Edit;
FieldByName((AnsiString)(TargetField)):= WorkBuffer;
Table1.Post;
Table1.Next;
Table1.EnableControls;
end;
finally
Table1.EnableControls;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);//第一个地址大写
begin
ForceCase('Addr1',Upper);
end;
procedure TForm1.Button2Click(Sender: TObject);//第二个地址大写
begin
ForceCase('Addr2',Upper);
end;
procedure TForm1.Button3Click(Sender: TObject);//第一个地址大小写互换
begin
ForceCase('Addr1',Upper);
end;
procedure TForm1.Button4Click(Sender: TObject);//第二个地址大小写互换
begin
ForceCase('Addr2',Upper);
end;
end.

错误提示如下:
[Error] Unit5.pas(67): '(' expected but ')' found
[Error] Unit5.pas(67): ')' expected but ';' found
[Error] Unit5.pas(70): Incompatible types: 'String' and 'PAnsiChar'
[Error] Unit5.pas(75): Incompatible types: 'String' and 'PAnsiChar'
[Error] Unit5.pas(77): '(' expected but ')' found
[Error] Unit5.pas(77): ')' expected but ';' found
[Error] Unit5.pas(81): '(' expected but ')' found
[Error] Unit5.pas(92): Constant object cannot be passed as var parameter







回复列表 (共2个回复)

沙发

哎!你看看他的错误提示定位在哪里?还有你是复制过来的,请注意全角和半角的区别,祝你好运!

板凳

源码太长我没仔细看。不过有个经验供你参考:
当过程名与单元名相同时,有可能造成你所说的错误信息。

我来回复

您尚未登录,请登录后再回复。点此登录或注册