SD王之項目文件:Stock.prj
有四個方法,如下:
1. function GetFileNameExcludeExt(const AFileName: string): string;
取得檔案名稱(不包含副檔名)
ExtractFileName(const FileName: string): string;
從包含路徑的文件名稱中分離出文件名(含副檔名)
參見:
ExpandFileName(const FileName: string): string;
包含完整路徑的文件名.若無路徑,則取當前路徑並附加上去.
ExtractFilePath(const FileName: string): string;
從包含路徑的文件名稱中分離出路徑.
LastDelimiter(const Delimiters, S: string): Integer;
判斷一個字符串中任何字符在另一字符串中最後出現的位置.如無則返回 0 .
AnsiStrRScan(Str: PChar; Chr: Char): PChar;
找出字符在字符串中最後出現的位置,並截取從這個位置開始至尾所有的字符串,並返回。
IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
判斷指定字符串是否出現在另一字符串指定位置上,若是則返回true,否則返回false.
文件名相關常量:
PathDelim 路徑分隔符 /
DriveDelim 盤符 :
PathSep 路徑分隔符 ;
常量: MaxInt = High(Integer);
2. procedure InitBufferMemory; // 初始化 Buffer
var
i: Integer;
begin
for i := 0 to 4 do
arrStock[i] := nil; // rrStock -- 個股Array, 於uMain中聲明為 TMarket 型
TickManager := TTickItemRecManager.Create; //
end;
3. function DoStockConvert(APath: string): Boolean; // Stock 轉換
var
IsConverted: string;
begin
Result := True;
IsConverted := GetSeting('DSTC', 'IsConverted'); // 獲得註冊表數據
if (IsConverted = '') or (IsConverted = 'False') then
begin
WriteSeting('DSTC', 'IsConverted', 'False');
end
else
begin // 若轉換則刪除 StockConvert.ini 和 StockConvert.exe
if FileExists('c:/StockConvert.ini') then
Windows.DeleteFile(PChar('c:/StockConvert.ini'));
if FileExists('c:/StockConvert.exe') then
Windows.DeleteFile(PChar('c:/StockConvert.exe'));
end;
end;
4. function CheckServerLink: Boolean; // 檢查是否連接服務器
5. 程序啟動
1. if ExeName <> 'Stock.exe' then ExeName := 'Stock.exe'; // 規定程序名稱為 Stock.exe,防止多重啟動聲動王
2. MutexName := ExtractFileName(ParamStr(0)); // 取得程序名稱
3. 檢查是否連接 Internet : CheckServerLink
4. F_Logo := TF_Logo.Create(Application, ExePath + VersionRec.Logo_jpg_Addr);
// 聲動王 Logo
5. InitBufferMemory; // 初始化Buffer
6. Application.CreateForm(TF_Main, F_Main); // 構建主窗體
7. Application.CreateForm(TF_Setup_1, F_Setup_1); // 構建“自選股”窗體
Application.CreateForm(TF_Setup_13, F_Setup_13); // 構建“我的帳簿”窗體
8. PostMessage(StockMutexHandle, CEXWM_BRINGWINDOWTOTOP, 0, 0); // 向主窗體發送消息
PostMessage(
hWnd :HWND, // handle of destination window , 接收消息的窗體 Handle
UINT Msg, // message to post ,接收到消息
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
): Boolean;