Delphi 慢过 VB?(50分)

  • 主题发起人 主题发起人 Deaton
  • 开始时间 开始时间
D

Deaton

Unregistered / Unconfirmed
GUEST, unregistred user!
学了四天 Delphi,做个程序,竟然比 VB 还慢。哪儿不对?请高手指教。

对应于VB的DoEvents的指令是哪条?

unit Main;

interface

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

type
TFormMain = class(TForm)
PanelMain: TPanel;
StatusBarMain: TStatusBar;
ProgressBarMain: TProgressBar;
BitBtnNew: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtnNewClick(Sender: TObject);
private
{私有过程和函数声明}
procedure ShowHint(Sender: TObject);
procedure UpdateProcessBar(intDone: Integer);
public
{ Public declarations }
end;

var
FormMain: TFormMain;

implementation

uses Data;

{$R *.DFM}

procedure TFormMain.FormCreate(Sender: TObject);
var
ZAppName : array[0..127] of char;
Hold : String ;
Found : HWND;
begin
Hold := Application.Title;
Application.Title := 'OnlyOne'
+ IntToStr(HInstance);
//暂时修改窗口标题

StrPCopy(ZAppName, Hold);
//原窗口标题
Found := FindWindow(nil, ZAppName);
//查找窗口
Application.Title := Hold;
//恢复窗口标题
if Found<>0 then begin
//若找到则激活已运行的程序并结束自身
ShowWindow(Found, SW_RESTORE);
Application.Terminate;
end;

Caption :=Application.Title;
{定位进度条}
with ProgressBarMain do
begin
Left :=StatusBarMain.Left;
Top :=StatusBarMain.Top;
Height :=StatusBarMain.Height;
Width :=StatusBarMain.Width;
end;
{通过引用自定义过程,获取当前的提示信息}
Application.OnHint :=ShowHint;
{$I-}
{改变到应用程序的目录}
ChDir(ExtractFilePath(Application.EXEName));
{$I+}
end;

procedure TFormMain.ShowHint(Sender: TObject);
begin
{提示用户当前的状态}
StatusBarMain.SimpleText := Application.Hint;
end;

procedure TFormMain.BitBtnNewClick(Sender: TObject);
var
v1,v2,v3,v4,v5 : Integer;
i : integer;
begin


{显示进度条}
with ProgressBarMain do
begin
Max :=65780;
Position :=0;
Visible :=True;
end;

{删除原有数据}
with DataModuleMain do
ADOConnectionMain.Execute('DELETE * FROM Data');

i:=1;
// DataModuleMain.ADOTableData.Open
with DataModuleMain.ADOTableData do begin
Open;
for v1 :=1 to 22 do
for v2 :=v1+1 to 23 do begin
for v3 :=v2+1 to 24 do
for v4 :=v3+1 to 25 do
for v5:=v4+1 to 26 do begin
Append;
Fields[0].Value :=i;
Fields[1].Value :=v1;
Fields[2].Value :=v2;
Fields[3].Value :=v3;
Fields[4].Value :=v4;
Fields[5].Value :=v5;
Fields[6].Value :=v1+v2+v3+v4+v5;

Update;
Inc(i);
end;
UpdateProcessBar(i);
end;
close;
end;

{DataModuleMain.ADOTableData.Recordset.AddNew;}

end;

procedure TFormMain.UpdateProcessBar(intDone: Integer);
begin
{更新进度条}
ProgressBarMain.Position :=intDone;
end;

end.



unit Data;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB;

type
TDataModuleMain = class(TDataModule)
ADOConnectionMain: TADOConnection;
ADOTableData: TADOTable;
private
{ Private declarations }
public
{ Public declarations }
end;

var
DataModuleMain: TDataModuleMain;

implementation

{$R *.DFM}

end.


VB 的代码:

Option Explicit

Private Sub cmdNew_Click()

Dim i As Long
Dim v1 As Byte
Dim v2 As Byte
Dim v3 As Byte
Dim v4 As Byte
Dim v5 As Byte

deWinner.cnWinner.Execute "DELETE FROM Data"
sbInfo.SimpleText = "正在构建数据,请稍候……"
With deWinner.rscmdDataRecorsdSet
.Open
i = 1
For v1 = 1 To 22
For v2 = v1 + 1 To 23
For v3 = v2 + 1 To 24
For v4 = v3 + 1 To 25
For v5 = v4 + 1 To 26
.AddNew
.Fields("ID") = i
.Fields("F1") = v1
.Fields("F2") = v2
.Fields("F3") = v3
.Fields("F4") = v4
.Fields("F5") = v5
.Fields("Sum") = v1 + v2 _
+ v3 + v4 + v5
i = i + 1
Next
Next
Next
.UpdateBatch adAffectAllChapters
DoEvents
Next
Next
.Close
End With
End Sub

Private Sub cmdNew_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
sbInfo.SimpleText = "重新构建全部数据组合序列"
End Sub

Private Sub Form_Load()
ChDrive App.Path
ChDir App.Path
Caption = App.ProductName & " " & App.Major & "." & App.Minor
deWinner.cnWinner.Open
End Sub

Private Sub Form_UNLoad()
deWinner.cnWinner.Close
End Sub


Private Sub fraButtons_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
sbInfo.SimpleText = "就绪"
End Sub

数据库为 Winner.mdb, 有一个表 Data, 字段 ID, F1,F2,F3,F4,F5 均可设为长整数。
P3-500 + Win98se , VB6用了6min, Delphi5 用了11min
 
又是这种话题
学了4天?
昏倒。。。。。。
多干活,少说话。
doEvents=Application.ProcessMessages
 
应于VB的DoEvents的指令是哪条?
Application.processMessage
 
多人接受答案了。
 

Similar threads

A
回复
0
查看
992
Andreas Hausladen
A
S
回复
0
查看
906
SUNSTONE的Delphi笔记
S
S
回复
0
查看
884
SUNSTONE的Delphi笔记
S
A
回复
0
查看
973
Andreas Hausladen
A
后退
顶部