In Delphi XE2, when creating a simple form with the Open button, the project works fine in Windows PE (version 3.0), and when creating the same form in Delphi XE, OpenDialog does not work !!! Good people help find out what the difference is ...

    2 answers 2

    If you have Delphi installed with source code, compare the Execute codes in different versions. For XE2, it is scattered across modules, like this:

    function TOpenDialog.Execute(ParentWnd: HWND): Boolean; begin Result := DoExecute(@GetOpenFileName, ParentWnd); end; 

     function GetOpenFileName; external commdlg32 name 'GetOpenFileNameW'; function GetOpenFileNameA; external commdlg32 name 'GetOpenFileNameA'; function GetOpenFileNameW; external commdlg32 name 'GetOpenFileNameW'; 

     function TOpenDialog.DoExecute(Func: Pointer; ParentWnd: HWND): Bool; const MultiSelectBufferSize = High(Word) - 16; OpenOptions: array [TOpenOption] of DWORD = ( OFN_READONLY, OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY, OFN_NOCHANGEDIR, OFN_SHOWHELP, OFN_NOVALIDATE, OFN_ALLOWMULTISELECT, OFN_EXTENSIONDIFFERENT, OFN_PATHMUSTEXIST, OFN_FILEMUSTEXIST, OFN_CREATEPROMPT, OFN_SHAREAWARE, OFN_NOREADONLYRETURN, OFN_NOTESTFILECREATE, OFN_NONETWORKBUTTON, OFN_NOLONGNAMES, OFN_EXPLORER, OFN_NODEREFERENCELINKS, OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_DONTADDTORECENT, OFN_FORCESHOWHIDDEN); OpenOptionsEx: array [TOpenOptionEx] of DWORD = (OFN_EX_NOPLACESBAR); var Option: TOpenOption; OptionEx: TOpenOptionEx; OpenFilename: TOpenFilename; function AllocFilterStr(const S: string): string; var P: PChar; begin Result := ''; if S <> '' then begin Result := S + #0; // double null terminators P := AnsiStrScan(PChar(Result), '|'); while P <> nil do begin P^ := #0; Inc(P); P := AnsiStrScan(P, '|'); end; end; end; var FileDialogWrapper: TFileDialogWrapper; TempFilter, TempFilename, TempExt: string; begin if (Win32MajorVersion >= 6) and UseLatestCommonDialogs and StyleServices.Enabled and (Template = nil) and not (Assigned(FOnIncludeItem) or Assigned(FOnClose) or Assigned(FOnShow)) then begin // This requires Windows Vista or later if Func = @GetOpenFileName then FileDialogWrapper := TFileOpenDialogWrapper.Create(Self) else FileDialogWrapper := TFileSaveDialogWrapper.Create(Self); try Result := FileDialogWrapper.Execute(ParentWnd); finally FileDialogWrapper.Free; end; Exit; end; FFiles.Clear; FillChar(OpenFileName, SizeOf(OpenFileName), 0); with OpenFilename do begin if (Win32MajorVersion >= 5) and (Win32Platform = VER_PLATFORM_WIN32_NT) or { Win2k } ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and (Win32MajorVersion >= 4) and (Win32MinorVersion >= 90)) then { WinME } lStructSize := SizeOf(TOpenFilename) else lStructSize := SizeOf(TOpenFilename) - (SizeOf(DWORD) shl 1) - SizeOf(Pointer); { subtract size of added fields } hInstance := SysInit.HInstance; TempFilter := AllocFilterStr(FFilter); lpstrFilter := PChar(TempFilter); nFilterIndex := FFilterIndex; FCurrentFilterIndex := FFilterIndex; if ofAllowMultiSelect in FOptions then nMaxFile := MultiSelectBufferSize else nMaxFile := MAX_PATH; SetLength(TempFilename, nMaxFile + 2); lpstrFile := PChar(TempFilename); FillChar(lpstrFile^, (nMaxFile + 2) * SizeOf(Char), 0); StrLCopy(lpstrFile, PChar(FFileName), nMaxFile); if (FInitialDir = '') and ForceCurrentDirectory then lpstrInitialDir := '.' else lpstrInitialDir := PChar(FInitialDir); lpstrTitle := PChar(FTitle); Flags := OFN_ENABLEHOOK; FlagsEx := 0; for Option := Low(Option) to High(Option) do if Option in FOptions then Flags := Flags or OpenOptions[Option]; if NewStyleControls then begin Flags := Flags xor OFN_EXPLORER; if (Win32MajorVersion >= 5) and (Win32Platform = VER_PLATFORM_WIN32_NT) or { Win2k } ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and (Win32MajorVersion >= 4) and (Win32MinorVersion >= 90)) then { WinME } for OptionEx := Low(OptionEx) to High(OptionEx) do if OptionEx in FOptionsEx then FlagsEx := FlagsEx or OpenOptionsEx[OptionEx]; end else Flags := Flags and not OFN_EXPLORER; TempExt := FDefaultExt; if (TempExt = '') and (Flags and OFN_EXPLORER = 0) then begin TempExt := ExtractFileExt(FFilename); Delete(TempExt, 1, 1); end; if TempExt <> '' then lpstrDefExt := PChar(TempExt); if (ofOldStyleDialog in Options) or not NewStyleControls then lpfnHook := DialogHook else lpfnHook := ExplorerHook; if Template <> nil then begin Flags := Flags or OFN_ENABLETEMPLATE; lpTemplateName := Template; if FTemplateModule <> 0 then hInstance := FTemplateModule; end; if Application.ModalPopupMode <> pmNone then begin FRedirector := TRedirectorWindow.Create(nil); with TRedirectorWindow(FRedirector) do begin FCommonDialog := Self; FFormHandle := ParentWnd; end; hWndOwner := FRedirector.Handle; end else hWndOwner := ApplicationMainHandle; Result := TaskModalDialog(Func, OpenFileName); if Result then begin GetFileNames(OpenFilename); if (Flags and OFN_EXTENSIONDIFFERENT) <> 0 then Include(FOptions, ofExtensionDifferent) else Exclude(FOptions, ofExtensionDifferent); if (Flags and OFN_READONLY) <> 0 then Include(FOptions, ofReadOnly) else Exclude(FOptions, ofReadOnly); FFilterIndex := nFilterIndex; end; end; end; 

      The question is written is not enough clear :) As I understand it, you want to create applications in DelphiXE for OSs other than Windows for PCs, in particular under WindowsPE so support for platforms other than Windows did not appear only in DelphiXE2 and only when using FireMonkey

      • You understand what's the matter, Delphi 7 also works fine! - mbx
      • Does not work on versions 2007-2010 and XE, but works on XE2 ... - mbx
      • I do not understand, describe the situation specifically desirable with the code. - SoftR
      • Yes, there is nothing to describe, I create a bare form with a button, the code on the button: begin if OpenDialog1.Execute then ShellExecute (Handle, nil, PChar (OpenDialog1.FileName), nil, nil, SW_SHOW); end; - mbx
      • Tested on different Delphi, works only on 7-ke and XE2. EXE-shnik going, the program works, but in WindowsPE just the file selection dialog does not appear ... - mbx