Шаг 5 - Пишем в файл

Наша задача будет произвести запись в файл. Итак, код:

theView = av.FindDoc("View1")

x=1
if (theView<>nil) then

	theTheme = theView.FindTheme("base.shp") 
	if (theTheme<>nil) then
		theFTab = theTheme.GetFTab
		shapeField  = theFTab.FindField( "Shape" )
		exportFile = LineFile.Make("c:\1.gen".AsFileName, #FILE_PERM_WRITE)

		for each recNum in theFTab
			currentShape = theFTab.ReturnValue( shapeField, recNum )
			pt=currentShape.ReturnCenter 
			Xvalue = pt.GetX.AsString
			Yvalue = pt.GetY.AsString
			outputLine = x.AsString+", "+Xvalue+", "+Yvalue
			exportFile.WriteElt( outputLine )
			x=x+1
		end

		exportFile.WriteElt( "END" )
		exportFile.Close
	else
		MsgBox.Info( "No Theme", "")
	end
else
	MsgBox.Info( "No View", "")
end

Что здесь нового, это создание файла.

exportFile = LineFile.Make("c:\1.gen".AsFileName, #FILE_PERM_WRITE)

Здесь имя есть и тип записи. После создания можно проводить запись. В данном случае пишется строка.

exportFile.WriteElt( outputLine )

А в самом конце закрываем файл.

exportFile.Close

Можно собирать и запускать. Будет сформирован GEN файл.

5_1.gif (4121 b)


Предыдущий Шаг | Следующий Шаг | Оглавление
Автор Каев Артем - 27.03.2002