Compartir a través de


Add Method (File Object)

Adds a file to a project.

Object.Add(cFileName)

Return Value

Object

Parameters

  • cFileName
    Specifies the name of the file to add to the project. An error is generated if the file you specify does not exist. The Project Manager window, if open, is refreshed after the file has been added.

Remarks

Applies To: Files Collection

The Add method is a method for the files collection. When a file is added to a project with the Add method, a File object is created for the file, and the File object is added to the Files collection.

An object reference to the newly added file is returned if the file is successfully added to the project. The null value is returned if the file can't be added to the project.

The QueryAddFile event occurs just before a file is added to a project. If NODEFAULT is specified in the QueryAddFile event, the file isn't added to the project.

Include NODEFAULT in the QueryAddFile event to prevent a file from being added to the project.

Example

The following example programmatically creates a Project and then builds an executable (EXE) from that Project. It uses the Add method to add program code to the project.

SET SAFETY OFF
LOCAL lcCode
TEXT TO lcCode NOSHOW
CLEAR
PUBLIC loForm

SET TALK OFF
SET DELETED ON
SET EXCLUSIVE OFF
SET CENTURY ON

ON SHUTDOWN clear events
loForm = CREATEOBJECT('Test1')
loForm.Show(0)
READ EVENTS
ON SHUTDOWN
RETURN

DEFINE CLASS Test1 as Form
 Top = 0
 Left = 0
 Width = 240
 Height = 150
 Caption = 'Add Method sample'
 ShowWindow = 2

 ADD OBJECT cmdClose as CommandButton WITH ;
  Caption = '\<Close', ;
  Top = 80, ;
  Left = 80, ;
  Height = 24, ;
  Width = 80

 ADD OBJECT lblTitle as Label WITH ;
  Top = 30, ;
  Left = 40, ;
  Height = 34, ;
  Width = 160, ;
  Caption = 'This sample was made programmatically.';
  WordWrap = .t.

 PROCEDURE Init
  SET TALK off
  ThisForm.AutoCenter = .t.
 ENDPROC
 PROCEDURE Unload
  CLEAR EVENTS
 ENDPROC
 PROCEDURE cmdClose.Click
  ThisForm.Release()
 ENDPROC
ENDDEFINE
ENDTEXT

STRTOFILE(lcCode, 'addsample.prg')
CREATE PROJECT 'AddSample' NOSHOW NOWAIT SAVE
LOCAL loPJX
loPJX = _VFP.ActiveProject
WITH loPJX
 .Files.Add('addsample.prg')
 .SetMain('addsample.prg')
 .Build('addsample.exe',3,.t.,.t.,.f.)
 .Close()
ENDWITH
RUN /n addsample.exe

See Also

Reference

File Object (Visual FoxPro)

QueryAddFile Event

NODEFAULT Command

Other Resources

Methods (Visual FoxPro)

Language Reference (Visual FoxPro)