Consultor Eletrônico



Kbase P130144: How to store a file into a MEMPTR and copying it to a LONGCHAR variable?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/05/2010
Status: Verified

GOAL:

How to store a file into a MEMPTR and copying it to a LONGCHAR variable?

GOAL:

Is there some sample code to store a file into a MEMPTR and copying it to a LONGCHAR variable?

FACT(s) (Environment):

OpenEdge 10.x
All Supported Operating Systems

FIX:

The following is a sample code on how to read a file into a MEMPTR and then copying it to a LONGCHAR variable:

DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE mPointerVariable AS MEMPTR NO-UNDO.
DEFINE VARIABLE lChar AS LONGCHAR VIEW-AS EDITOR LARGE SIZE 60 BY 1.

ASSIGN cFileName = "myfile".

RUN LoadFileToMempointer (INPUT cFileName, OUTPUT mPointerVariable).

COPY-LOB mPointerVariable TO lchar CONVERT SOURCE CODEPAGE "ISO8859-1" TARGET CODEPAGE "utf-8".
/* COPY-LOB mPointerVariable TO lchar. */
SET-SIZE(mPointerVariable) = 0.

MESSAGE length(lChar)
VIEW-AS ALERT-BOX INFO BUTTONS OK.


PROCEDURE LoadFileToMempointer:
DEFINE INPUT PARAMETER ipcFileName AS CHARACTER NO-UNDO.
DEFINE OUTPUT PARAMETER opMempointer AS MEMPTR NO-UNDO.

FILE-INFO:FILE-NAME = ipcFileName.
SET-SIZE(opMempointer) = FILE-INFO:FILE-SIZE.

INPUT FROM VALUE(ipcFileName) BINARY NO-MAP.
IMPORT UNFORMATTED opMempointer.
INPUT CLOSE.
END PROCEDURE.