服务端主窗口
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TlHelp32, ExtCtrls, DB, DBClient, Grids, DBGrids,
ADODB, Provider, AppEvnts;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
QryPooling: TADOQuery;
DataSetProvider1: TDataSetProvider;
ClientDataSet1: TClientDataSet;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormShow(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
private
{ Private declarations }
function GetPoolingData: OleVariant;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses AdoconnectPool;
{$R *.dfm}
function GetDirFiles(sPath: string): TStringList;
var
SearchRec: TSearchRec;
iFound: Integer;
sList: TStringList;
begin
sList := TStringList.Create;
if Pos('*.', sPath) = 0 then
iFound := FindFirst(sPath + '*.*', faAnyFile - faDirectory, SearchRec)
else
iFound := FindFirst(sPath, faAnyFile - faDirectory, SearchRec);
while iFound = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') and
(SearchRec.Attr <> faDirectory) then
sList.Add(SearchRec.Name);
iFound := FindNext(SearchRec);
end;
FindClose(SearchRec);
Result:= sList;
end;
function FindProcess(AFileName: string): boolean;
var
hSnapshot: THandle;//用于获得进程列表
lppe: TProcessEntry32;//用于查找进程
Found: Boolean;//用于判断进程遍历是否完成
begin
try
Result :=False;
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//获得系统进程列表
lppe.dwSize := SizeOf(TProcessEntry32);//在调用Process32First API之前,需要初始化lppe记录的大小
Found := Process32First(hSnapshot, lppe);//将进程列表的第一个进程信息读入ppe记录中
while Found do
begin
if ((UpperCase(ExtractFileName(lppe.szExeFile))=UpperCase(AFileName)) or (UpperCase(lppe.szExeFile )=UpperCase(AFileName))) then
begin
Result :=True;
end;
Found := Process32Next(hSnapshot, lppe);//将进程列表的下一个进程信息读入lppe记录中
end;
except
Result :=False;
Exit;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if not FindProcess('scktsrvr.exe') then
WinExec('scktsrvr.exe', SW_SHOWNORMAL);
Self.DoubleBuffered :=True;
DBGrid1.DoubleBuffered :=True;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if Application.MessageBox('Is sure close the system?', PChar(Application.Title), MB_YESNO +
MB_ICONQUESTION) = IDYES then
begin
CanClose := True;
end
else
CanClose := False;
end;
function TForm1.GetPoolingData: OleVariant;
begin
Result := null;
QryPooling.ConnectionString := AdoconnectPool.g_ini.ReadString('ado','connstr','');
QryPooling.Close;
QryPooling.SQL.Clear;
QryPooling.SQL.Text := 'select poolingType, maxNum, createdNum, usedNum from sys_pooling';
QryPooling.Open;
if QryPooling.Active and not QryPooling.IsEmpty then
begin
Result := DataSetProvider1.Data;
QryPooling.Close;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ClientDataSet1.Data := GetPoolingData;
ClientDataSet1.IndexFieldNames := 'poolingType'; // set primary key
end;
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.message = 8888 then // pooling state
begin
case Msg.wParam of
11:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOConnection']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.FieldByName('createdNum').AsInteger := ClientDataSet1.FieldByName('createdNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
12:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOConnection']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger -1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
13:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOConnection']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
21:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOQuery']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('createdNum').AsInteger := ClientDataSet1.FieldByName('createdNum').AsInteger +1;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
22:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOQuery']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger -1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
23:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOQuery']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
31:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOStoredProc']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('createdNum').AsInteger := ClientDataSet1.FieldByName('createdNum').AsInteger +1;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
32:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOStoredProc']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger -1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
33:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['ADOStoredProc']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
41:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['DatasetProvider']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('createdNum').AsInteger := ClientDataSet1.FieldByName('createdNum').AsInteger +1;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
42:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['DatasetProvider']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger -1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
43:
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['DatasetProvider']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
51: // createNew
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['COMThread']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('createdNum').AsInteger := ClientDataSet1.FieldByName('createdNum').AsInteger +1;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
52:
begin // unlock
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['COMThread']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger -1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
53: // indexof
begin
ClientDataSet1.DisableControls;
ClientDataSet1.FindKey(['COMThread']);
ClientDataSet1.Edit;
ClientDataSet1.FieldByName('usedNum').AsInteger := ClientDataSet1.FieldByName('usedNum').AsInteger +1;
ClientDataSet1.Post;
ClientDataSet1.EnableControls;
end;
end;
end else inherited;
end;
end.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2012/01/11/2319990.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?