?? include.pas
字號:
{
=====================================================================
* 軟件名稱:PC與數(shù)控機床通信程序
* 單元名稱:資源單元
* 單元作者:彭為 (pwzyp@fjsm.net)
* 備 注:用到了線程進行發(fā)送
* 開發(fā)平臺:PWin2000 SERVER + Delphi 7.0
* 兼容測試:PWin9X/2000/XP + Delphi 6/7
* 采用控件:Raize 3.12 ,SPCOMM
* 修改記錄:V1.0 by pengwei
=====================================================================
}
unit Include;
interface
uses SysUtils, Classes, Windows, Messages, Forms, ShellAPI, Dialogs, WinSock;
resourcestring
//字符串資源
sCopyright = 'CopyRight 湖南師范大學工學院 2004';
sMainCaption = '數(shù)控機床通訊程序-單機版';
sExportCaption = '發(fā)送數(shù)據(jù)至數(shù)控機床';
sImportCaption = '從數(shù)控機床接收數(shù)據(jù)';
sFileNewCaption = '導入文件至通信服務(wù)器';
sFileSaveasCaption = '導出文件生成磁盤備份';
sConfigCaption = '系統(tǒng)配置';
sFileInfocaption = '文件相關(guān)屬性查看修改';
sKey = '連接的設(shè)備編號';
sValue = '設(shè)備名稱';
sTitleAsk = '詢問';
sTitleInfo = '信息';
sTitleErr = '錯誤';
sOpenDataError = '打開數(shù)據(jù)庫錯誤,請檢查當前目錄是否有server.Mdb文件' + chr(13)
+ '點擊確定退出系統(tǒng)';
sIsStopService =
'停止服務(wù)將導致用戶無法使用客戶端上傳數(shù)控命令文件,請選擇是否停止?';
sInfoClose = '關(guān)閉服務(wù)器將導致用戶無法使用數(shù)控機床通訊程序,您確認嗎?';
sNotFile = '數(shù)據(jù)文件不存在,請檢查!';
sFileEmpty = '文件內(nèi)容是空的';
sBreak = '正在接收數(shù)據(jù),是否中斷這一過程';
sNotFileName = '您沒有選擇導入的文件名,請?zhí)钊胍獙氲奈募窂叫畔?#039;;
sNotSaveasfile = '您沒有選擇導出的文件名,請?zhí)钊胍獙С龅奈募窂叫畔?#039;;
sDeleteFile = '注意:本操作將把該程序所有信息全部刪除,且無法恢復' + Chr(13) +
'建議您做好備份工作,用【導出文件】功能導出該程序,' + chr(13) +
'需要時再用【導入文件】功能恢復。' +
Chr(13) + '請確認是否刪除?';
sErrReceive1 = '串口接收數(shù)據(jù)出現(xiàn)錯誤';
const
MaxChannels = 20;
MaxFilelens = 1024;
Timeout = 15; //10秒為超時時間
Debug = True;
function ComPortAvailable(Port: PChar): Boolean;
function Confirm(prompt: string): boolean;
procedure ShowMsg(Msg: string);
procedure WinAbout(const AppName, Stuff: string);
function GetLocalIP: string;
//20030915 Pengwei 文件GUID創(chuàng)建函數(shù) 從ole32.dll引出
function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll';
function StringFromCLSID(const clsid: TGUID; out psz: PWideChar): HResult;
stdcall; external 'ole32.dll';
function CLSIDFromString(psz: PWideChar; out clsid: TGUID): HResult; stdcall;
external 'ole32.dll';
procedure CoTaskMemFree(pv: Pointer); stdcall; external 'ole32.dll';
//以下是自定義函數(shù),用于轉(zhuǎn)換
function GUIDToString(const ClassID: TGUID): string;
function StringToGUID(const StrClassID: string): TGUID;
//測試是否有文件尾,是否符合發(fā)送規(guī)范
function TestEOF(const Content: string): boolean;
implementation
function ComPortAvailable(Port: PChar): Boolean;
var
DeviceName: array[0..80] of Char;
ComFile: THandle;
begin
StrPCopy(DeviceName, Port);
ComFile := CreateFile(DeviceName, GENERIC_READ or GENERIC_WRITE, 0, nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
Result := ComFile <> INVALID_HANDLE_VALUE;
CloseHandle(ComFile);
end;
function Confirm(prompt: string): boolean;
begin
result := MessageBox(application.handle,
pchar(prompt),
'請確認', mb_ICONQuestion + mb_YesNo) = idYes;
end;
procedure ShowMsg(Msg: string);
begin
MessageBox(application.handle,
pchar(Msg),
pchar(Application.title),
mb_ICONInformation);
end;
procedure WinAbout(const AppName, Stuff: string);
var
{$IFNDEF WIN32}
szApp, szStuff: array[0..255] of Char;
{$ENDIF}
Wnd: HWnd;
Icon: HIcon;
begin
if Application.MainForm <> nil then
Wnd := Application.MainForm.Handle
else
Wnd := 0;
Icon := Application.Icon.Handle;
if Icon = 0 then
Icon := LoadIcon(0, IDI_APPLICATION);
{$IFDEF WIN32}
ShellAbout(Wnd, PChar(AppName), PChar(Stuff), Icon);
{$ELSE}
StrPLCopy(szApp, AppName, SizeOf(szApp) - 1);
StrPLCopy(szStuff, Stuff, SizeOf(szStuff) - 1);
ShellAbout(Wnd, szApp, szStuff, Icon);
{$ENDIF}
end;
function GetLocalIP: string;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of char;
I: Integer;
GInitData: TWSADATA;
begin
WSAStartup($101, GInitData);
try
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do
begin
result := StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
finally
WSACleanup;
end;
end;
//以下是自定義函數(shù),用于轉(zhuǎn)換
function GUIDToString(const ClassID: TGUID): string;
var
P: PWideChar;
begin
StringFromCLSID(ClassID, P);
Result := P;
CoTaskMemFree(P);
end;
function StringToGUID(const StrClassID: string): TGUID;
begin
CLSIDFromString(PWideChar(WideString(StrClassID)), Result);
end;
//測試是否有文件尾
function TestEOF(const Content: string): Boolean;
var
EofChar: Char;
begin
EofChar := Content[Length(Content)];
Result := (Eofchar = Chr(26));
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -