In connection with the discovery of the sqlite database in Delphi, I began to consider the types of input parameters. I changed the code

procedure TMainWindow.OpenDialog1Close(Sender: TObject); begin partofconnectstring:=ExtractFilePath(String(OpenDialog1.FileName))+ExtractFileName(String(OpenDialog1.FileName)); Label1.Caption:=partofconnectstring; Edit1.Text:=partofconnectstring; ConnectToDatabase(partofconnectstring, SQLConnection1); CreateObjs(SQLConnection1, DBSchema); //IBDatabase1.DatabaseName:='127.0.0.1:'+ChangeFileExt(OpenDialog1.FileName, '.fdb'); end; 

Since in the ConnectToDatabase procedure the input parameter is string , the question arises how to convert OpenDialog1.FileName to string , since the above code does not work. When debugging, partofconnectstring displayed as an empty string.

    1 answer 1

    If my memory serves me, then OpenDialog1.FileName already returns a string, and no conversion is needed.

    I only advise you to do it differently. do it all in a separate procedure (for example, MyProc), and call it like this:

     procedure TForm1.MyProc(FileName: string); begin partofconnectstring:=ExtractFilePath(FileName)+ExtractFileName(FileName); Label1.Caption:=partofconnectstring; Edit1.Text:=partofconnectstring; ConnectToDatabase(partofconnectstring, SQLConnection1); CreateObjs(SQLConnection1, DBSchema); //IBDatabase1.DatabaseName:='127.0.0.1:'+ChangeFileExt(FileName, '.fdb'); end; procedure TForm1.AnotherProc; begin if OpenDialog1.Execute() then if FileExists(OpenDialog1.FileName) then MyProc(OpenDialog1.FileName); end; 

    And it is better to do not a procedure, but a function. And to handle after it connection errors to the database.