程序代码:
CLEAR ALL CLOSE DATABASES ALL frmMain = CREATEOBJECT("C_Form") frmMain.Show READ EVENTS CLEAR RETURN DEFINE CLASS C_Form AS Form Caption = "" Width = 600 Height = 400 AutoCenter = .T. ADD OBJECT Button1 AS CommandButton WITH Caption = "需定位的文件", Width = 100, Height = 25 ADD OBJECT Text1 AS TextBox WITH Value = "", Height = 25 ADD OBJECT List1 AS C_ShowFile NOINIT WITH Visible = .F. PROCEDURE Arrange WITH ThisForm.Button1 .Top = 5 .Left = 5 ENDWITH WITH ThisForm.Text1 .Top = ThisForm.Button1.Top .Left = ThisForm.Button1.Left + ThisForm.Button1.Width + 5 .Width = ThisForm.Width - .Left - 5 ENDWITH WITH ThisForm.List1 .Top = ThisForm.Button1.Top + ThisForm.Button1.Height + 5 .Left = 5 .Height = ThisForm.Height - .Top - 5 .Width = ThisForm.Width - .Left - 5 ENDWITH ENDPROC PROCEDURE Activate ThisForm.Arrange ENDPROC PROCEDURE Resize ThisForm.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC PROCEDURE Button1.CLick WITH ThisForm .Text1.Value = GETFILE() .List1.Init(.Text1.Value) .List1.Visible = .T. ENDWITH ENDPROC PROCEDURE Text1.Valid IF !EMPTY(This.Value) WITH ThisForm.List1 .Init(This.Value) .Visible = .T. ENDWITH ENDIF ENDPROC ENDDEFINE DEFINE CLASS C_ShowFile AS ListBox PROCEDURE Init(tcFileName AS Character) LOCAL lcPath AS Character LOCAL laFiles[1,5] LOCAL lnIndex AS Integer LOCAL lnPos AS Integer IF (PCOUNT() > 0) .AND. (VARTYPE(tcFileName) == "C") .AND. !EMPTY(tcFileName) tcFileName = ALLTRIM(UPPER(tcFileName)) IF FILE(tcFileName) lcPath = JUSTPATH(tcFileName) IF ADIR(laFiles, lcPath + "\*.*") > 0 WITH This .Clear .ColumnCount = 4 .ColumnWidths = "200,100,100,100" FOR lnIndex = 1 TO ALEN(laFiles,1) .AddListItem(laFiles[lnIndex,1], lnIndex, 1) .AddListItem(TRANSFORM(laFiles[lnIndex,2], "999,999,999,999"), lnIndex, 2) .AddListItem(DTOC(laFiles[lnIndex,3]), lnIndex, 3) .AddListItem(laFiles[lnIndex,4], lnIndex, 4) IF (lcPath + "\" + laFiles[lnIndex,1]) == tcFileName lnPos = lnIndex ENDIF NEXT .ListIndex = lnPos ENDWITH ENDIF ELSE This.Clear ENDIF ENDIF ENDPROC ENDDEFINE
[ 本帖最后由 TonyDeng 于 2012-1-8 23:55 编辑 ]
授人以渔,不授人以鱼。