Einzelnen Beitrag anzeigen

Fukiszo
(Gast)

n/a Beiträge
 
#4

AW: IDE geht kaputt bei TFileSaveDialog und Vererbung

  Alt 29. Jan 2018, 19:53
Ich glaub das gehört hier nicht hin da ja ein IDE/VCL fehler beschrieben wurde,
ich selbst nutz selten Delphi's VCL variante sondern diese hier:

Delphi-Quellcode:
{
How to use OpenSaveFileDialog
OpenDialog will have "Read-Only" Flag activated by default
while SaveDialog can "Overwrite" or "CreateNew"
  For example:
  1. to display the "OpenDialog" for text files
    s := 'aaa.txt';
    if OpenSaveFileDialog(Application.Handle, 'txt', 'Text Files|*.txt', 'c:\',
    'Select text file', s, True) then
      ShowMessage(s + ' file was selected for open')

  2. to display the "Save dialog":
    s := 'data.dbf';
    if OpenSaveFileDialog(Application.Handle, 'dbf', 'dBase tables|*.dbf|All files|*.*',
    'c:\', 'Select table', s, False) then
      ShowMessage(s + ' table was selected for save')
}

function OpenSaveFileDialog(ParentHandle: THandle; const DefExt, Filter, InitialDir, Title: string; var FileName: string; IsOpenDialog: Boolean): Boolean;
 function CharReplace(const Source: string; oldChar, newChar: Char): string;
  var
   i: Integer;
  begin
   Result := Source;
   for i := 1 to Length(Result) do
    if Result[i] = oldChar then
      Result[i] := newChar
  end;
var
  ofn: TOpenFileName;
  szFile: array[0..MAX_PATH] of Char;
begin
  Result := False;
  FillChar(ofn, SizeOf(TOpenFileName), #0);
  with ofn do
  begin
    lStructSize := SizeOf(TOpenFileName);
    hwndOwner := ParentHandle;
    lpstrFile := szFile;
    nMaxFile := SizeOf(szFile);
    if (Title <> '') then
      lpstrTitle := PChar(Title);
    if (InitialDir <> '') then
      lpstrInitialDir := PChar(InitialDir);
    StrPCopy(lpstrFile, FileName);
    lpstrFilter := PChar(CharReplace(Filter, '|', #0)+#0#0);
    if DefExt <> 'then
      lpstrDefExt := PChar(DefExt);
    if IsOpenDialog then Flags := OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_LONGNAMES or OFN_PATHMUSTEXIST or OFN_READONLY or OFN_NODEREFERENCELINKS or OFN_NONETWORKBUTTON or OFN_DONTADDTORECENT or OFN_FORCESHOWHIDDEN
   else Flags := OFN_EXPLORER or OFN_CREATEPROMPT or OFN_OVERWRITEPROMPT or OFN_LONGNAMES or OFN_PATHMUSTEXIST or OFN_NODEREFERENCELINKS or OFN_NONETWORKBUTTON or OFN_DONTADDTORECENT or OFN_FORCESHOWHIDDEN;
    FlagsEx := OFN_EX_NOPLACESBAR;
  end;
  if IsOpenDialog then
  begin
    if GetOpenFileName(ofn) then
    begin
      Result := True;
      FileName := StrPas(szFile);
    end;
  end
  else
  begin
    if GetSaveFileName(ofn) then
    begin
      Result := True;
      FileName := StrPas(szFile);
    end;
  end
end;
Achtung, nicht Unicode konform, selber ändern wenn nötig.

Grüße
  Mit Zitat antworten Zitat