带有动态文件类型过滤器的SYSTEM-DIALOG GET-FILE

时间:2018-10-04 19:49:10

标签: openedge progress-4gl

使用OpenEdge 11.7和Windows 7,我正在使用以下工作代码搜索磁盘文件:

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE lChose AS LOGICAL NO-UNDO.

SYSTEM-DIALOG GET-FILE cFileName
    FILTERS "Text Files (*.txt)" "*.txt", "Comma-Separated Value Files (*.csv)" "*.csv"
    UPDATE lChose.

是否可以使用变量动态构建过滤器列表?我已经尝试过了,但是行不通:

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilters AS CHARACTER NO-UNDO.
DEFINE VARIABLE lChose AS LOGICAL NO-UNDO.

cFilters = '"Text Files (*.txt)" "*.txt", "Comma-Separated Value Files (*.csv)" "*.csv"'.

SYSTEM-DIALOG GET-FILE cFileName
    FILTERS cFilters
    UPDATE lChose. 

我也尝试过:

FILTERS VALUE(cFilters)

两者都返回“无法理解”错误(198)。甚至可以做到吗?

2 个答案:

答案 0 :(得分:2)

ABL及其有趣的语法...文档指出,每个过滤器标签和过滤器文件规范本身都是一个表达式。您可以传递空对,这些对将被忽略。所以这在这里有效-数组元素5-10为空并被压缩:

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilters AS CHARACTER NO-UNDO EXTENT 10.
DEFINE VARIABLE lChose AS LOGICAL NO-UNDO.

ASSIGN 
    cFilters[1] = "Text Files (*.txt)" 
    cFilters[2] = "*.txt"
    cFilters[3] = "Comma-Separated Value Files (*.csv)"
    cFilters[4] = "*.csv" .

SYSTEM-DIALOG GET-FILE cFileName
    FILTERS cFilters[1] cFilters[2], cFilters[3] cFilters[4], cFilters[5] cFilters[6], cFilters[7] cFilters[8], cFilters[9] cFilters[10]   
    UPDATE lChose. 

或使用.NET替代:

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilters AS CHARACTER NO-UNDO.
DEFINE VARIABLE lChose AS LOGICAL NO-UNDO.

cFilters = "Text Files (*.txt)|*.txt|Comma-Separated Value Files (*.csv)|*.csv".

DEFINE VARIABLE oSystemDialog AS System.Windows.Forms.OpenFileDialog NO-UNDO . 
DEFINE VARIABLE oDialogResult AS System.Windows.Forms.DialogResult NO-UNDO . 

oSystemDialog = NEW System.Windows.Forms.OpenFileDialog () .
oSystemDialog:Filter = cFilters .
oSystemDialog:CheckFileExists = TRUE . 
oSystemDialog:RestoreDirectory  = TRUE .

WAIT-FOR oSystemDialog:ShowDialog () SET oDialogResult . 

IF Progress.Util.EnumHelper:AreEqual (oDialogResult, System.Windows.Forms.DialogResult:OK) THEN
DO:
    ASSIGN lChose = TRUE 
           cFileName = oSystemDialog:FileName. 
END.
ELSE 
    ASSIGN lChose = FALSE 

答案 1 :(得分:1)

似乎有可能写

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilter1a AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilter1b AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilter2a AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFilter2b AS CHARACTER NO-UNDO.
DEFINE VARIABLE lChoose AS LOGICAL NO-UNDO.

assign
    cFilter1a = "Text Files (*.txt)"
    cFilter1b = "*.txt"
    cFilter2a = "Comma-Separated Value Files (*.csv)"
    cFilter2b = "*.csv"
.

SYSTEM-DIALOG GET-FILE cFileName
    FILTERS cFilter1a cFilter1b, cFilter2a cFilter2b
    UPDATE lChoose.

对您可能有用或可能不有用。