Consultor Eletrônico



Kbase 17999: SAMPLE PROGRAM How to read save a file with an editor widget
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/20/1999
SAMPLE PROGRAM How to read save a file with an editor widget

INTRODUCTION:
=============

The following program uses the READ-FILE and SAVE-FILE methods to read
and save a file using the editor widget.

Please refer to the Progress Language Reference manual for a full
description of these methods.

REFERENCES TO WRITTEN DOCUMENTATION:
====================================

-PROGRESS Language Reference

SAMPLE PROGRAM:
===============

DEF VAR wfile-name AS CHAR FORMAT "X(25)" LABEL "File Name".
DEF VAR weditor AS CHAR
VIEW-AS EDITOR INNER-CHARS 50 INNER-LINES 20 SCROLLBAR-VERTICAL.
DEF BUTTON wopen LABEL "&Open".
DEF BUTTON wread LABEL "&Read".
DEF BUTTON wsave LABEL "&Save".
DEF VAR wlog AS LOGICAL.

FORM wopen HELP "Type a file name." SKIP
wfile-name wread wsave SKIP
weditor NO-LABEL WITH FRAME xx THREE-D SIDE-LABELS.

ON CHOOSE OF wopen DO:
ASSIGN wfile-name.
SYSTEM-DIALOG GET-FILE wfile-name
TITLE "Choose a file to edit ..."
FILTERS "Procedures (*.p)" "*.p",
"Text Files (*.txt)" "*.txt",
"All Files (*.*)" "*.*"
MUST-EXIST
USE-FILENAME
UPDATE wlog.
IF wlog THEN DO:
DISPLAY wfile-name WITH FRAME xx.
IF NOT weditor:READ-FILE(wfile-name:SCREEN-VALUE) THEN
MESSAGE "The file could not be loaded."
VIEW-AS ALERT-BOX ERROR.
END.
END.

ON CHOOSE OF wread DO:
wlog = weditor:READ-FILE(wfile-name:SCREEN-VALUE).
IF NOT wlog THEN
MESSAGE "The file could not be loaded."
VIEW-AS ALERT-BOX ERROR.
END.

/* NOTE:The following code has some optimizations of usage of wlog. */
ON CHOOSE OF wsave DO:
FILE-INFO:FILE-NAME = wfile-name:SCREEN-VALUE.

wlog = FILE-INFO:PATHNAME = ?.

IF NOT wlog THEN
MESSAGE FILE-INFO:PATHNAME "already exists." SKIP
"Do you want to replace it?"
VIEW-AS ALERT-BOX QUESTION BUTTONS YES-NO
UPDATE wlog.
IF wlog THEN
IF NOT weditor:SAVE-FILE(wfile-name:SCREEN-VALUE) THEN
MESSAGE "The file could not be saved."
VIEW-AS ALERT-BOX ERROR.
END.

UPDATE wopen wfile-name wread wsave weditor WITH FRAME xx.

KBase #- 17999

EAG June 1998