【delphi开源代码栏目提醒】:网学会员鉴于大家对delphi开源代码十分关注,论文会员在此为大家搜集整理了“fMemoryTableMain.pas”一文,供大家参考学习
unit fMemoryTableMain;
interface
uses
SysUtils, Types, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, ExtCtrls, DBCtrls, DB, IdGlobal, Windows;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
DBGrid1: TDBGrid;
btnCreateMemoryTable: TButton;
lbTimes: TListBox;
btnSearchData: TButton;
Label1: TLabel;
edtID: TEdit;
Label2: TLabel;
edtValue: TEdit;
dsMemoryTable: TDataSource;
dbgMemoryTable: TDBGrid;
procedure btnCreateMemoryTableClick(Sender: TObject);
procedure btnSearchDataClick(Sender: TObject);
private
{ Private declarations }
lStart : Longint;
lEnd : Longint;
procedure CreateMemoryTable;
procedure FillTempData;
procedure InsertData(const iID : Integer; const sValue : String);
procedure ApplyData;
procedure StartTime;
procedure EndTime;
procedure ShowAppMsg(const sMsg : String);
function GetRunTime : double;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses udmMemoryTable;
{$R *.dfm}
procedure TForm1.CreateMemoryTable;
begin
with dmMemoryTable.scdsMemory do
begin
with FieldDefs.AddFieldDef do
begin
DataType := ftInteger;
Name := 'TID';
end;
with FieldDefs.AddFieldDef do
begin
DataType := ftString;
Size := 20;
Name := 'TSValue';
end;
with IndexDefs.AddIndexDef do
begin
Fields := 'TID';
Name := 'idxTID';
end;
CreateDataSet;
IndexDefs.Update;
IndexName := 'idxTID';
end;
end;
procedure TForm1.btnCreateMemoryTableClick(Sender: TObject);
begin
StartTime;
CreateMemoryTable;
FillTempData;
EndTime;
ShowAppMsg('建立内存数据表和数据时期:' + FloatToStr(GetRunTime));
end;
procedure TForm1.FillTempData;
begin
InsertData(1, 'DataSnap');
InsertData(2, 'WebSnap');
InsertData(3, 'Web Service');
InsertData(4, 'SOAP');
InsertData(5, 'XML');
InsertData(6, 'Interface');
InsertData(7, 'COM+');
InsertData(8, '
Delphi.NET');
InsertData(9, 'CBuilder.
NET');
InsertData(10, 'JBuilder');
InsertData(11, 'VisiBroker');
InsertData(12, 'Borland AppServer');
end;
procedure TForm1.ApplyData;
begin
dmMemoryTable.scdsMemory.ApplyUpdates(0);
end;
procedure TForm1.InsertData(const iID: Integer; const sValue: String);
begin
with dmMemoryTable.scdsMemory do
begin
Insert;
FieldByName('TID').Value := iID;
FieldByName('TSValue').Value := sValue;
Post;
end;
end;
procedure TForm1.EndTime;
begin
lEnd := GetTickCount;
end;
function TForm1.GetRunTime: double;
begin
Result := (lEnd - lStart) / 1000.0;
end;
procedure TForm1.StartTime;
begin
lStart := GetTickCount;
end;
procedure TForm1.ShowAppMsg(const sMsg: String);
begin
lbTimes.Items.Add(sMsg);
end;
procedure TForm1.btnSearchDataClick(Sender: TObject);
begin
StartTime;
edtValue.Text := dmMemoryTable.scdsMemory.Lookup('TID', edtID.Text, 'TSValue');
EndTime;
ShowAppMsg('搜寻数据时间:' + FloatToStr(GetRunTime));
end;
end.