FileOpenDialogScript

Ukázka dialogu pro otevření souboru

Popis

Skript zobrazí dialog pro otevření souboru a zobrazí cestu k vybranému souboru.
declare function DialogsCreate dll "ScriptEx" (string): integer
declare function DialogsExecute dll "ScriptEx" (integer, integer): boolean
declare procedure DialogsFree dll "ScriptEx" (var integer)
declare function DialogsGetStringProp dll "ScriptEx" (integer, string): string
declare procedure DialogsSetStringProp dll "ScriptEx" (integer, string, string)

script FileOpenDialogScript(): boolean
var
  FileName: string
  FileOpenDialog: integer
  FileTypes: string
begin
  FileOpenDialog := DialogsCreate("TFileOpenDialog")
  DialogsSetStringProp(FileOpenDialog, "DefaultFolder", "c:\Users\Public\Downloads")

  FileTypes := "["
  FileTypes += "  {"
  FileTypes += "    ""displayName"": ""Všechny soubory"", "
  FileTypes += "    ""fileMask"": ""*.*"" "
  FileTypes += "  },"
  FileTypes += "  {"
  FileTypes += "    ""displayName"": ""Textové dokumenty (*.txt)"", "
  FileTypes += "    ""fileMask"": ""*.txt"" "
  FileTypes += "  }"
  FileTypes += "]"
  DialogsSetStringProp(FileOpenDialog, "FileTypes", FileTypes)

  result := DialogsExecute(FileOpenDialog, 0)

  if result then
    FileName := DialogsGetStringProp(FileOpenDialog, "FileName")
    write(FileName)
  end

  DialogsFree(FileOpenDialog)
end