我有以下代码,所有代码需要做的是检查车辆列表并删除每个注册中的空格,但在更改之前,它应该检查以确保修改后的注册不存在。以下代码是我正在使用的:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, cxLookAndFeelPainters, StdCtrls, cxButtons, Gauges, DB,
DBTables, StrUtils;
type
TfrmMain = class(TForm)
prgTotal: TGauge;
btnStart: TcxButton;
tblVeh: TTable;
tblVehRegNo: TStringField;
procedure btnStartClick(Sender: TObject);
private
procedure OpenTable(pTable: TTable);
procedure CloseTable(pTable: TTable; pPost: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain : TfrmMain;
lvRegLst : TStringList;
lvTblSize : Integer;
lvOrigReg : String;
lvNewReg : String;
lvTest : integer;
implementation
{$R *.dfm}
procedure TfrmMain.btnStartClick(Sender: TObject);
begin
btnStart.Enabled := False;
lvRegLst := TStringList.Create;
// Open Tables
tblVeh.Open;
tblVeh.First;
// Set progress
prgTotal.MinValue := 0;
lvTblSize := tblVeh.RecordCount;
prgTotal.MaxValue := tblVeh.RecordCount;
btnStart.Caption := 'Parsing Registration Numbers...';
// Conversion
while not tblVeh.Eof do
begin
lvRegLst.Add(tblVehRegNo.AsString);
tblVeh.Next;
prgTotal.AddProgress(1);
Application.ProcessMessages;
end;
tblVeh.First;
lvTest := lvRegLst.Count;
prgTotal.Progress := 0;
btnStart.Caption := 'Removing Spaces...';
while not tblVeh.Eof do
begin
lvOrigReg := tblVehRegNo.AsString;
lvNewReg := AnsiReplaceStr(lvOrigReg,' ','');
if lvRegLst.IndexOf(lvNewReg) = -1 then
begin
tblVeh.Edit;
tblVehRegNo.AsString := lvNewReg;
prgTotal.AddProgress(1);
tblVeh.Post;
end;
tblVeh.Next;
prgtotal.AddProgress(1);
Application.ProcessMessages;
end;
// Close Tables
tblVeh.Edit;
tblVeh.Post;
tblVeh.Close;
btnStart.Caption := '&Start Conversion';
btnStart.Enabled := True;
end;
我已经浏览了代码,一切看起来都很好,它成功地更改了车辆的注册,但是当之后查看表格时,它没有进行任何更改。