在主窗口单元中<br>const<br> MapName = 'ExportLY map';<br><br>Type<br> TUserMsg = Record<br> serverName : string[255];<br> DatabaseName : string[255];<br> end;<br><br> PUserMsg = ^TUserMsg;<br><br> hMap: THandle;<br> pInfo: Pointer;<br> MapSize: Integer = SizeOf(TUserMsg);<br><br><br>procedure CreateMap;<br>begin<br> hMap := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE or SEC_COMMIT,<br> 0, MapSize, MapName);<br>end;<br><br>procedure ReleaseMap;<br>begin<br> CloseHandle(hMap);<br>end;<br><br>procedure SaveServerName;<br> var<br> MapInfo : TUserMsg;<br> hCurMap: THandle;<br>begin<br><br> hCurMap := OpenFileMapping(FILE_MAP_WRITE, True, MapName);<br> pInfo := MapViewOfFile(hCurMap, FILE_MAP_WRITE, 0, 0, MapSize);<br> MapInfo.serverName := ParamStr(1);<br> MapInfo.DatabaseName := ParamStr(2);<br> Move(MapInfo, pInfo^, MapSize);<br> UnmapViewOfFile(pInfo);<br> CloseHandle(hCurMap);<br><br>end;<br>// 从map中获取信息<br>procedure LoadServerName;<br> var<br> MapInfo : TUserMsg;<br> hCurMap : THandle;<br>begin<br><br> //<br> hCurMap := OpenFileMapping(FILE_MAP_WRITE, True, MapName);<br> pInfo := MapViewOfFile(hcurMap, FILE_MAP_WRITE, 0, 0, MapSize);<br><br> MapInfo := TUserMsg(pInfo^);<br> SystemParam.ServerName := MapInfo.serverName;<br> SystemParam.DatabaseName := MapInfo.DataBaseName;<br> UnmapViewOfFile(pInfo);<br> CloseHandle(hCurMap);<br><br>end;<br><br>在工程单元中:<br>var<br> MapInfo: TUserMsg;<br>begin<br><br> Application.Initialize;<br> Application.Title := '导出';<br> hmutex:=createmutex(nil, false, 'LYExport2000');<br> ret:=getlasterror;<br> if ret=error_already_exists then<br> begin<br> releasemutex(hmutex);<br> CloseHandle(hMutex);<br> <br> if ParamCount >= 2 then<br> begin<br> SystemParam.ServerName := ParamStr(1);<br> SystemParam.DataBaseName := ParamStr(2);<br> SaveServerName; // 写入map<br> end;<br> <br> Application.Terminate;<br> Exit;<br> end;<br> Application.CreateForm(Tfm_export, fm_export);<br> Application.ShowMainForm := False;<br> Application.Run;<br>end.