Jump to content
Henry Olive

Server Data Path

Recommended Posts

Good Day,

Delphi 10.3


To Connect my Database (FB3)  i use an INI file (it is in my EXE Path) which is like below

[DataPath]

Dir=MySrv:c:\MyApp\Data\    ( I fill the database name in Delphi )

 

In my program there is a Menu which shows (open)  the BackUp Folder to the user,  with below code

BackUpPath := MyIniFile.ReadString('DataPath', 'Dir', '') + 'BackUp';  // MySrv:c:\MyApp\Data\BackUp

ShellExecute(Handle, 'Open', PChar(BackUpPath), Nil, Nil, SW_SHOWNORMAL);

Since BackUpPath = MySrv:c:\MyApp\Data\BackUp ,  above ShellExecute command doesnt work

ShellExecute requires just  c:\MyApp\Data\BackUp   portion of the BackUpPath  (Server's Local Path)
 

I can do it with below codes , and i get correct result with below RightWord variable and ShellExecute works correctly

but I think there should be a better way
 

S:=  MySrv:c:\MyApp\Data\BackUp

if Pos('c:\',S) > 0 then
     X:=Pos('c:\',S) else
     X:=Pos('C:\',S);
  LeftWord:=Copy(S,1,X-1);
  RightWord:=Copy(S,X,Length(S));  which is  c:\MyApp\Data\BackUp 


Thank You
 

Share this post


Link to post

I would suggest to store "server" and "database folder" as separate fileds in your INI.

Server=MySrv:

Dir=C:\MyApp\Data\

 

It is much easier than to properly split it later. (App installed on another drive than C : , database on linux server, embedded database with empty server name etc.) 

Edited by Vandrovnik

Share this post


Link to post

Just break the string by ":" and then use proper filename functions upon the right part (ExtractFilePath etc)

Edited by Fr0sT.Brutal

Share this post


Link to post
11 minutes ago, Fr0sT.Brutal said:

Just break the string by ":" and then use proper filename functions upon the right part (ExtractFilePath etc)

This will not work with connection string for embedded Firebird.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×