--- oup/rewrite/DataAccess/ConnectionManager.pas 2007/01/18 17:15:59 93 +++ oup/current/DataAccess/ConnectionManager.pas 2007/02/22 00:37:39 112 @@ -17,12 +17,14 @@ type function GetConnectionCount: Integer; function GetConnection(ConnectionID: Integer): TDataAccess; function GetConnectionByIndex(Index: Integer): TDataAccess; + function GetConnectionIndex(ConnectionID: Integer): Integer; procedure RemoveConnection(ArrayIndex: Integer); protected public property Count: Integer read GetConnectionCount; property Connection[ConnectionID: Integer]: TDataAccess read GetConnection; property ConnectionByIndex[Index: Integer]: TDataAccess read GetConnectionByIndex; + property ConnectionIndexByID[ConnectionID: Integer]: Integer read GetConnectionIndex; property OnCoonnectionListChanged: TConnectionListChangedEvent read FConnectionListChanged write FConnectionListChanged; constructor Create; @@ -32,10 +34,15 @@ type function CloseConnectionByIndex(Index: Integer; var Msg: TStatusMessages): Boolean; overload; function CloseConnection(ID: Integer; var Msg: TStatusMessages): Boolean; overload; function CloseConnection(FileName: String; var Msg: TStatusMessages): Boolean; overload; + function FileOpened(FileName: String): Integer; published end; +var + ConManager: TConnectionManager; + + implementation uses SysUtils, Dialogs; @@ -50,6 +57,20 @@ begin Result := Length(FConnections); end; +function TConnectionManager.GetConnectionIndex(ConnectionID: Integer): Integer; +var + i: Integer; +begin + Result := -1; + if Count > 0 then + for i := 0 to Count - 1 do + if ConnectionByIndex[i].ConnectionID = ConnectionID then + begin + Result := i; + Break; + end; +end; + function TConnectionManager.GetConnection(ConnectionID: Integer): TDataAccess; var i: Integer; @@ -129,9 +150,9 @@ begin ext := UpperCase(ExtractFileExt(FileName)); - if ext = 'ODB' then + if ext = '.OLDB' then backend := DB_ADB - else if ext = 'DAT' then + else if ext = '.DAT' then backend := DB_ONI else begin @@ -152,6 +173,7 @@ begin begin FLastID := FConnections[i].ConnectionID; Result := FLastID; + Msg := SM_OK; end else begin @@ -159,7 +181,7 @@ begin FConnections[i].Free; FConnections[i] := nil; SetLength(FConnections, Length(FConnections) - 1); - Msg := SM_UnknownError; + Msg := CreateMsg; end; end; @@ -239,4 +261,23 @@ begin end; +function TConnectionManager.FileOpened(FileName: String): Integer; +var + i: Integer; +begin + Result := -1; + if Length(FConnections) > 0 then + for i := 0 to High(FConnections) do + if FConnections[i].FileName = FileName then + begin + Result := FConnections[i].ConnectionID; + Exit; + end; +end; + + +initialization + ConManager := TConnectionManager.Create; +finalization + ConManager.Free; end.