物理删除数据库记录(10分)

  • 主题发起人 主题发起人 jsxjd
  • 开始时间 开始时间
如果你是在DLEPHI写ADO的话,那删记录还不是跟用BDE一样呀,比如:
ADOTABLE1。DELETE这样不就行了吗?
 
用BDE物理删除我知道,我的BDE无法使用 FoxPro 的 Free Table ODBC,
上面有详细做法。不知是什么原因 。
 
BDE没有必要再通过ODBC去访问数据库。这样只是在ODBC外面封装了一层BDE的东东,无法
完全实现BDE的所有功能。
 
用这个代码就可以将数据库压缩了,实现了你的物理删除,
uses DAO2000,ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
dao: Variant;
CopyFlag:Boolean;
begin
dao := CreateOleObject('DAO.DBEngine.36');
dao.CompactDatabase('c:/WorkOne.mdb','C:/WorkOne_1.mdb');
DeleteFile(PChar('c:/WorkOne.mdb'));
copyFile(pChar('C:/WorkOne_1.mdb'),Pchar('C:/WorkOne.mdb'),CopyFlag);
DeleteFile(PChar('c:/WorkOne_1.mdb'));

end;

请注意一下该句话
dao := CreateOleObject('DAO.DBEngine.36');
字符串 'DAO.DBEngine.36'可能在你的机器中就不是了。
打开注册表,搜索‘DAO.DBEngine',看看后面的是否为36,有些机器为35,主要是DAO的版本问题。
改为你机器的DAO版本后就能运行了。
否则会提示你’字符串错误'.

 
to Block_K_E:
不是access ,是 foxpro 的 FreeTable
 
多人接受答案了。
 
物理刪除和邏輯刪除是不一樣的,反正這個問題也是搞死人!
 
1. 在DLL中创建模态和非模态窗口并传递参数
//////////////// DLL /////////////////////////////////
library MyForm;
uses
SysUtils,
Classes,
Forms,
controls,
Dialogs,
MyModal in 'MyModal.pas' {MyMForm},
ModLess in 'ModLess.pas' {MyModless};

{$R *.RES}
type THandle = Integer;


procedure showMyForm(p:pchar;handle:THandle);stdcall;
var
myForm:TMyMForm;

begin
Application.Handle:=handle;
myForm:=TMyMForm.MyCreate(p) ;
myForm.showmodal;
myForm.free;
end;

procedure showMyModLess(p:pchar;handle:THandle);stdcall;
begin
if not assigned(noMod) then
begin
Application.Handle:=handle;
NoMod:=TMyModLess.MyCreate(p) ;
end;
NoMod.show;
end;
exports showMyForm,showMyModless;
begin
FreeAndNil(NoMod);
end.


///////////////////////////// 模态窗口 ////////////////////////////////////////////
unit MyModal;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMyMForm = class(TForm)
Edit1: TEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
FP:pointer;
{ Private declarations }
public
{ Public declarations }
constructor MyCreate(s:pchar);
end;
implementation
{$R *.DFM}
{ TMyMForm }
constructor TMyMForm.MyCreate(s: pchar);
begin
inherited Create(nil);
fp:=s;
Edit1.Text:=ShortString(fp^);
end;

procedure TMyMForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShortString(fp^):=Edit1.Text;
end;

procedure TMyMForm.FormCreate(Sender: TObject);
begin
icon.LoadFromFile ('winupd.ico');
end;

end.


////////////////////////////////// 非模态窗口 //////////////////////////////
unit ModLess;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMyModless = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
FP:pointer;
public
{ Public declarations }
constructor MyCreate(s:pchar);

end;

var
NoMod:TMyModLess;

implementation

{$R *.DFM}

{ TMyModless }

constructor TMyModless.MyCreate(s: pchar);
begin
inherited Create(nil);
fp:=s;
Edit1.Text:=ShortString(fp^);
end;

procedure TMyModless.FormCreate(Sender: TObject);
begin
icon.LoadFromFile ('winupd.ico');
end;

procedure TMyModless.Button1Click(Sender: TObject);
begin
ShortString(fp^):=Edit1.Text;
end;

procedure TMyModless.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=caFree ;
NoMod:=nil;
end;

end.

//////////////////////// 调用程序 /////////////////////////////////////
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure showMyForm(p:pchar;handle:THandle);stdcall;external 'MyForm.dll';
procedure showMyModLess(p:pchar;handle:THandle);stdcall;external 'MyForm.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
s:ShortString;
begin
s:=Edit1.text;
showmyform(@s,handle);
Edit1.text:=s;
end;

var
s:ShortString='ABCDEF';
procedure TForm1.Button2Click(Sender: TObject);
begin
showmyModLess(@s,handle);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
showmessage(s);
end;

end.
 
后退
顶部