gpt4 book ai didi

delphi - 如果扩展名已知,如何在 DoExecute TFileSaveDialog 事件中设置 FileTypeIndex?

转载 作者:行者123 更新时间:2023-12-03 15:56:58 27 4
gpt4 key购买 nike

如果文件扩展名已知,如何在 TFileSaveDialog DoExecute 事件中将扩展名转换为 FileTypeIndex?

   function TIEWin7FileSaveDialog.DoExecute: Bool;
begin
...
{Set FileType (filter) index}
iWideTextension := ExtractFileExt(FileName);
FileTypeIndex := ???ExtensionToFileTypeIndex(iWideExtension);???
FileDialog.SetFileTypeIndex(FileTypeIndex);
...
end;

最佳答案

至少没有显式函数可以执行您想要的操作,因为一种文件类型可能包含在多个文件类型掩码中,因此您只能迭代 FileTypes并检查文件类型是否包含或等于 FileMask如下图所示:

function FindFirstFileType(FileDialog: TCustomFileDialog;
const FileExt: string): UINT;
var
TypeIndex: Integer;
ExtIndex: Integer;
ExtArray: TStringDynArray;
begin
Result := 0;
for TypeIndex := 0 to FileDialog.FileTypes.Count - 1 do
begin
ExtArray := SplitString(FileDialog.FileTypes[TypeIndex].FileMask, ';');
for ExtIndex := 0 to High(ExtArray) do
if ExtArray[ExtIndex] = FileExt then
begin
Result := TypeIndex;
Break;
end;
end;
end;

以及用法(注意输入必须与过滤器掩码完全匹配):

procedure TForm1.Button1Click(Sender: TObject);
var
I: UINT;
begin
I := FindFirstFileType(FileOpenDialog1, '*.pas');
end;

关于delphi - 如果扩展名已知,如何在 DoExecute TFileSaveDialog 事件中设置 FileTypeIndex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571170/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com