Loading files from database

we load all script files (project, script, form) from database. We have structured storage like directories and we have problem with managing events in TIDEEngine. There are two problems:

  1. IDEEngine tries to load project ini file from expanded path and next calll DoLoadFile
    It's problem because code may accidentaly load some real file (it is security problem also)
function TIDEEngine.LoadProject: boolean;
  MI: TMemIniFile;
  ANewFile: TIDEProjectFile;
  AFileName: string;
  c, total: integer;
  AMainUnitName: string;
  SL: TStrings;
  AFileContent: string;
  AFileLanguage: integer;
  {Loads the list of files in the project, fill the files collection, and make all visible}
  MI := TMemIniFile.Create(GetFullProjectFileName); --------------------------------------- HERE
    {Load the text from file. Do it in two steps because we want to call OnLoadFile event
     in case the file content is loaded from a blob or something like that}
    SL := TStringList.Create;
      AFileContent := '';
      if DoLoadFile(iftProject, GetFullProjectFileName, AFileContent, nil) then
        SL.Text := AFileContent

      {After loading file content, now set the content of memory ini file for retrieving information}

  1. Code still tries to expand filename using OS expand function for real files.
    We can not load files from database, becuse we get wrong filename in OnLoadFile event. Here is a code snippet to demonstrate problem:
procedure TForm1.IDEEngine1CheckValidFile(Sender: TObject; IDEFileType: TIDEFileType; AFileName: string; var AValid: Boolean);
 //Here we check in database for validity

procedure TForm1.IDEEngine1LoadFile(Sender: TObject; IDEFileType: TIDEFileType; AFileName: string; var AContent: string; AFile: TIDEProjectFile; var Handled: Boolean);
 // Here we need to load file from database, but filename is not valid = is expanded

procedure TForm1.IDEEngine1OpenDialog(Sender: TObject; IDEFileType: TIDEFileType; var AFileName: string; var ResultOk, Handled: Boolean);
 //here we have dialog for browse database structure

Code should not intercept file names in this situation.


I don't understand why this is a problem? The content of the file is overwritten by the DoLoadFile event, so all content is cleared anyway.

I also don't understand what is the problem here. The file name is provided expanded, yes, and it's up to you to "interpret" its meaning and "convert" it to your database structure to properly load the content.

I'm afraid I need mode detailed information about the actual problem, ideally a project reproducing the issue.

Yes, ini file is overwriten, but it's not good practice to open something I don't want. I think you can change it to TMemIniFile.Create('') without any problem.

I cannot right interpret expanded filename. If my OpenDialog returns


then OpenFile tries to open (for example):


This is fail. I cannot determine rigth portion of file.

Ok, fair enough.

You can simply parse and check the right part of the string. No files are involved here, just strings. You can set the file name you want in OpenDialog, thus you can set it to an absolute value so it's easier for you to parse.

But I cannot determine "right part" of string. Is it Debug\ProjA\project.ssproj or Win32\Debug\ProjA ... etc OpenFile has only AFileName parameter to determine right file.

Which absolute value are you recommend? UNC name is not good (but works) because of expandig.

What is the problem with UNC name, if it works. There will be no file involved if you are doing 100% from database.

UNC work ok and we use this approach. Problem is with


we discussed above. Windows takes about 2sec to scan unc path even if do not exists. If we change it to Create('') then it is acceptable solution. The second problem (minor) is that this solution is based on fact, that OS function for path expanding do not support UNC so we use side effect of OS function. This is not good practice.


We will change (actually have already changed) that line to use Create(''). You can safely change it there at your side, next version will include this change.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.