Project

General

Profile

spreadsheet_demo_issues.p

Sergey Ivanovskiy, 11/05/2026 12:38 PM

Download (13.7 KB)

 
1
/*------------------------------------------------------------------------------
2
  spreadsheet_demo_issues.p  the spreadsheet issues met in the topic 15 demo
3

    
4
  One sheet, one case per issue of spreadsheet_demo_issues.textile.
5
  Every case writes its values to spreadsheet_demo_issues.out in the working
6
  directory (deploy/client in FWD), so the FWD and OpenEdge runs can be
7
  compared line by line.  Run it on FWD and on OpenEdge (OE-F1) the same way.
8

    
9
  Automatic, at start:
10
    1  style range:  A1 1234 "#,##0", B1 0.25 "0.0%", then SetFont on A1:B1;
11
                     reports FormattedTextRC and NumberFormat of A1 and B1
12
    2  alignment:    A2 "right" with SetAlignment(4, ...); visual only
13
    5  scrolling:    SetActiveCell(4, 2), then TopRow = 1, LeftCol = 1;
14
                     reports TopRow and LeftCol after each step
15
    6b read after write, no event: B9 = 20 (EntryRC), then NumberRC of C9
16
                     (=SUM(B9)) right away
17

    
18
  Interactive (keys; the program starts with B4 active):
19
    3  type abc in B4, Enter: EndEdit sets Cancel = 1.  Press Escape if the
20
       editor stays open.
21
    4  Down to B5, type abc, Enter: EndEdit sets the edit string to 999.
22
    6  Down, Down to B8: SelChange writes B7 = 20 (EntryRC) and reads C7
23
       (=SUM(B7)) right away, again after Recalc.
24
    then press Report: the final state of B4, C4, B5, C5, B7, C7, A1, B1,
25
    TopRow and LeftCol.
26

    
27
  Every EndEdit and SelChange is logged with the active cell and, for
28
  EndEdit, the edit string and the values of the edited cell and its sum.
29

    
30
  Preprocessor names the OpenEdge wrapper defines first (&GLOBAL-DEFINE):
31
    OE-F1     run on OpenEdge (32-bit prowin32) with the real Formula One OCX,
32
               loaded from wrx/wssheet.wrx (metacom)
33
------------------------------------------------------------------------------*/
34

    
35
&SCOPED-DEFINE F1 chCtrlFrame:F1Book
36

    
37
DEFINE VARIABLE wWin        AS WIDGET-HANDLE NO-UNDO.
38
DEFINE VARIABLE CtrlFrame   AS WIDGET-HANDLE NO-UNDO.
39
DEFINE VARIABLE chCtrlFrame AS COM-HANDLE    NO-UNDO.
40
DEFINE VARIABLE lEventDone  AS LOGICAL       NO-UNDO.
41

    
42
DEFINE VARIABLE cLog AS CHARACTER NO-UNDO
43
   VIEW-AS EDITOR SCROLLBAR-VERTICAL SIZE 150 BY 10.
44

    
45
DEFINE STREAM sOut.
46

    
47
DEFINE BUTTON btnReport LABEL "Report".
48
DEFINE BUTTON btnExit   LABEL "Exit".
49

    
50
DEFINE FRAME fMain
51
   btnReport btnExit SKIP(0.5)
52
   cLog NO-LABEL
53
   WITH SIDE-LABELS NO-BOX THREE-D AT COLUMN 1 ROW 1 SIZE 158 BY 32.
54

    
55
ON CHOOSE OF btnReport IN FRAME fMain
56
DO:
57
   RUN report ("final").
58
END.
59

    
60
ON CHOOSE OF btnExit IN FRAME fMain
61
DO:
62
   APPLY "CLOSE" TO THIS-PROCEDURE.
63
END.
64

    
65
RUN create-ui.
66

    
67
OUTPUT STREAM sOut TO VALUE("spreadsheet_demo_issues.out").
68
&IF DEFINED(OE-F1) = 0 &THEN
69
RUN log-line ("# spreadsheet_demo_issues FWD").
70
&ELSE
71
RUN log-line ("# spreadsheet_demo_issues OE-F1").
72
&ENDIF
73

    
74
RUN build-sheet.
75
RUN case-1.
76
RUN case-2.
77
RUN case-6b.
78
RUN case-5.
79
RUN log-line ("# now: abc + Enter in B4 (Escape if the editor stays open), Down, abc + Enter in B5, "
80
              + "Down, Down to B8, then Report").
81

    
82
WAIT-FOR CLOSE OF THIS-PROCEDURE.
83

    
84
OUTPUT STREAM sOut CLOSE.
85
RUN destroy-ui.
86

    
87
/*------------------------------------------------------------------------------
88
  Creates the test window and the spreadsheet.
89
------------------------------------------------------------------------------*/
90
PROCEDURE create-ui:
91
   CREATE WINDOW wWin ASSIGN
92
      TITLE     = "spreadsheet_demo_issues"
93
      HEIGHT    = 33
94
      WIDTH     = 160
95
      THREE-D   = yes
96
      SENSITIVE = yes
97
      HIDDEN    = yes.
98
   CURRENT-WINDOW = wWin.
99

    
100
   CREATE CONTROL-FRAME CtrlFrame ASSIGN
101
      FRAME     = FRAME fMain:HANDLE
102
      ROW       = 13
103
      COLUMN    = 1
104
      HEIGHT    = 19
105
      WIDTH     = 158
106
      TAB-STOP  = yes
107
      HIDDEN    = yes
108
      SENSITIVE = yes.
109

    
110
&IF DEFINED(OE-F1) = 0 &THEN
111
   /* FWD ignores the .wrx, so the OCX name of the event procedures (sheet.F1Book.EndEdit) comes from
112
      the NAME */
113
   CtrlFrame:NAME = "sheet.F1Book".
114
&ELSE
115
   CtrlFrame:NAME = "sheet".
116
&ENDIF
117
   chCtrlFrame = CtrlFrame:COM-HANDLE.
118
&IF DEFINED(OE-F1) = 0 &THEN
119
   chCtrlFrame:F1Book:LoadControls("", "spreadsheet").
120
&ELSE
121
   chCtrlFrame:LoadControls(SEARCH("wrx/wssheet.wrx"), "ssheet").
122
&ENDIF
123

    
124
   VIEW FRAME fMain IN WINDOW wWin.
125
   ENABLE btnReport btnExit cLog WITH FRAME fMain.
126
   VIEW wWin.
127
   CtrlFrame:HIDDEN = no.
128
END PROCEDURE.
129

    
130
/*------------------------------------------------------------------------------
131
  Deletes the test window.
132
------------------------------------------------------------------------------*/
133
PROCEDURE destroy-ui:
134
   IF VALID-HANDLE(CtrlFrame) THEN
135
      DELETE WIDGET CtrlFrame.
136
   IF VALID-HANDLE(wWin) THEN
137
      DELETE WIDGET wWin.
138
END PROCEDURE.
139

    
140
/*------------------------------------------------------------------------------
141
  Appends a line to the editor and to the result file.
142
------------------------------------------------------------------------------*/
143
PROCEDURE log-line:
144
   DEFINE INPUT PARAMETER pcLine AS CHARACTER NO-UNDO.
145

    
146
   cLog = cLog + pcLine + CHR(10).
147
   DISPLAY cLog WITH FRAME fMain.
148
   PUT STREAM sOut UNFORMATTED pcLine SKIP.
149
END PROCEDURE.
150

    
151
/*------------------------------------------------------------------------------
152
  One cell: TypeRC | [TextRC] | [FormattedTextRC] | NumberRC | [NumberFormat]
153
------------------------------------------------------------------------------*/
154
FUNCTION cell-state RETURNS CHARACTER (INPUT piRow AS INTEGER, INPUT piCol AS INTEGER):
155
   DEFINE VARIABLE iType AS INTEGER   NO-UNDO.
156
   DEFINE VARIABLE cText AS CHARACTER NO-UNDO.
157
   DEFINE VARIABLE cFmtd AS CHARACTER NO-UNDO.
158
   DEFINE VARIABLE dNum  AS DECIMAL   NO-UNDO.
159
   DEFINE VARIABLE cFmt  AS CHARACTER NO-UNDO.
160

    
161
   iType = {&F1}:TypeRC(piRow, piCol) NO-ERROR.
162
   cText = {&F1}:TextRC(piRow, piCol) NO-ERROR.
163
   cFmtd = {&F1}:FormattedTextRC(piRow, piCol) NO-ERROR.
164
   dNum  = {&F1}:NumberRC(piRow, piCol) NO-ERROR.
165
   {&F1}:SetSelection(piRow, piCol, piRow, piCol) NO-ERROR.
166
   cFmt  = {&F1}:NumberFormat NO-ERROR.
167

    
168
   RETURN CHR(64 + piCol) + STRING(piRow)
169
          + " | " + STRING(iType)
170
          + " | [" + cText + "]"
171
          + " | [" + cFmtd + "]"
172
          + " | " + STRING(dNum)
173
          + " | [" + cFmt + "]".
174
END FUNCTION.
175

    
176
/*------------------------------------------------------------------------------
177
  One cell without touching the selection, safe inside EndEdit (SetSelection
178
  there crashes prowin32 with Formula One): TypeRC | [TextRC] | NumberRC
179
------------------------------------------------------------------------------*/
180
FUNCTION cell-value RETURNS CHARACTER (INPUT piRow AS INTEGER, INPUT piCol AS INTEGER):
181
   DEFINE VARIABLE iType AS INTEGER   NO-UNDO.
182
   DEFINE VARIABLE cText AS CHARACTER NO-UNDO.
183
   DEFINE VARIABLE dNum  AS DECIMAL   NO-UNDO.
184

    
185
   iType = {&F1}:TypeRC(piRow, piCol) NO-ERROR.
186
   cText = {&F1}:TextRC(piRow, piCol) NO-ERROR.
187
   dNum  = {&F1}:NumberRC(piRow, piCol) NO-ERROR.
188

    
189
   RETURN CHR(64 + piCol) + STRING(piRow)
190
          + " | " + STRING(iType)
191
          + " | [" + cText + "]"
192
          + " | " + STRING(dNum).
193
END FUNCTION.
194

    
195
/*------------------------------------------------------------------------------
196
  The sheet for all cases.
197
------------------------------------------------------------------------------*/
198
PROCEDURE build-sheet:
199
   DEFINE VARIABLE iRow AS INTEGER NO-UNDO.
200

    
201
   /* cases 3 and 4: a number referenced by a formula */
202
   {&F1}:TextRC(3, 1)    = "EndEdit".
203
   {&F1}:TextRC(4, 1)    = "3 cancel".
204
   {&F1}:TextRC(5, 1)    = "4 edit string".
205
   DO iRow = 4 TO 5:
206
      {&F1}:NumberRC(iRow, 2)  = 33500.
207
      {&F1}:FormulaRC(iRow, 3) = "SUM(B" + STRING(iRow) + ")".
208
      {&F1}:SetSelection(iRow, 2, iRow, 3).
209
      {&F1}:NumberFormat = "#,##0".
210
   END.
211

    
212
   /* case 6: event; case 6b: no event */
213
   {&F1}:TextRC(7, 1)    = "6 SelChange".
214
   {&F1}:NumberRC(7, 2)  = 10.
215
   {&F1}:FormulaRC(7, 3) = "SUM(B7)".
216
   {&F1}:TextRC(8, 1)    = "go here".
217
   {&F1}:TextRC(9, 1)    = "6b no event".
218
   {&F1}:NumberRC(9, 2)  = 10.
219
   {&F1}:FormulaRC(9, 3) = "SUM(B9)".
220

    
221
   /* rows below, so that the sheet can scroll */
222
   DO iRow = 11 TO 60:
223
      {&F1}:NumberRC(iRow, 2) = iRow.
224
   END.
225
END PROCEDURE.
226

    
227
/*------------------------------------------------------------------------------
228
  1: SetFont on a range whose cells have different number formats.
229
------------------------------------------------------------------------------*/
230
PROCEDURE case-1:
231
   {&F1}:NumberRC(1, 1) = 1234.
232
   {&F1}:NumberRC(1, 2) = 0.25.
233
   {&F1}:SetSelection(1, 1, 1, 1).
234
   {&F1}:NumberFormat = "#,##0".
235
   {&F1}:SetSelection(1, 2, 1, 2).
236
   {&F1}:NumberFormat = "0.0%".
237
   RUN log-line ("1 before | " + cell-state(1, 1) + " || " + cell-state(1, 2)).
238

    
239
   {&F1}:SetSelection(1, 1, 1, 2).
240
   {&F1}:SetFont("Arial", 10, TRUE, FALSE, FALSE, FALSE, RGB-VALUE(0, 0, 255), FALSE, FALSE).
241
   RUN log-line ("1 after SetFont A1:B1 | " + cell-state(1, 1) + " || " + cell-state(1, 2)).
242
   RUN log-line ("1 expected | B1 keeps [25.0%] and [0.0%]; A1 and B1 bold blue (screenshot)").
243
END PROCEDURE.
244

    
245
/*------------------------------------------------------------------------------
246
  2: SetAlignment right; visual only (screenshot).
247
------------------------------------------------------------------------------*/
248
PROCEDURE case-2:
249
   {&F1}:TextRC(2, 1) = "right".
250
   {&F1}:SetSelection(2, 1, 2, 1).
251
   {&F1}:SetAlignment(4, FALSE, 2, 0) NO-ERROR.
252
   RUN log-line ("2 SetAlignment(4) on A2 | " + (IF ERROR-STATUS:ERROR THEN "ERR" ELSE "done")
253
                 + " | expected: right aligned (screenshot)").
254
END PROCEDURE.
255

    
256
/*------------------------------------------------------------------------------
257
  5: scrolling: SetActiveCell, then TopRow and LeftCol.  Leaves B4 active for
258
  the interactive cases.
259
------------------------------------------------------------------------------*/
260
PROCEDURE case-5:
261
   DEFINE VARIABLE iTop  AS INTEGER NO-UNDO.
262
   DEFINE VARIABLE iLeft AS INTEGER NO-UNDO.
263

    
264
   {&F1}:SetActiveCell(4, 2).
265
   iTop  = {&F1}:TopRow NO-ERROR.
266
   iLeft = {&F1}:LeftCol NO-ERROR.
267
   RUN log-line ("5 after SetActiveCell(4, 2) | TopRow " + STRING(iTop) + " | LeftCol " + STRING(iLeft)).
268

    
269
   {&F1}:TopRow  = 1.
270
   {&F1}:LeftCol = 1.
271
   iTop  = {&F1}:TopRow NO-ERROR.
272
   iLeft = {&F1}:LeftCol NO-ERROR.
273
   RUN log-line ("5 after TopRow = 1, LeftCol = 1 | TopRow " + STRING(iTop) + " | LeftCol " + STRING(iLeft)
274
                 + " | expected 1, 1; A1 visible at the top left (screenshot)").
275
END PROCEDURE.
276

    
277
/*------------------------------------------------------------------------------
278
  6b: a read right after a write, outside any sheet event.
279
------------------------------------------------------------------------------*/
280
PROCEDURE case-6b:
281
   DEFINE VARIABLE dSum AS DECIMAL NO-UNDO.
282

    
283
   {&F1}:EntryRC(9, 2) = "20".
284
   dSum = {&F1}:NumberRC(9, 3).
285
   RUN log-line ("6b no event: B9 = 20, then C9 | " + STRING(dSum) + " | expected 20").
286
END PROCEDURE.
287

    
288
/*------------------------------------------------------------------------------
289
  The final state, on Report.
290
------------------------------------------------------------------------------*/
291
PROCEDURE report:
292
   DEFINE INPUT PARAMETER pcWhen AS CHARACTER NO-UNDO.
293

    
294
   DEFINE VARIABLE iTop  AS INTEGER NO-UNDO.
295
   DEFINE VARIABLE iLeft AS INTEGER NO-UNDO.
296

    
297
   RUN log-line ("# " + pcWhen + ": cell | TypeRC | [TextRC] | [FormattedTextRC] | NumberRC | [NumberFormat]").
298
   RUN log-line ("1 " + cell-state(1, 1)).
299
   RUN log-line ("1 " + cell-state(1, 2)).
300
   RUN log-line ("3 " + cell-state(4, 2)).
301
   RUN log-line ("3 " + cell-state(4, 3)).
302
   RUN log-line ("4 " + cell-state(5, 2)).
303
   RUN log-line ("4 " + cell-state(5, 3)).
304
   RUN log-line ("6 " + cell-state(7, 2)).
305
   RUN log-line ("6 " + cell-state(7, 3)).
306
   RUN log-line ("6b " + cell-state(9, 2)).
307
   RUN log-line ("6b " + cell-state(9, 3)).
308
   iTop  = {&F1}:TopRow NO-ERROR.
309
   iLeft = {&F1}:LeftCol NO-ERROR.
310
   RUN log-line ("5 TopRow " + STRING(iTop) + " | LeftCol " + STRING(iLeft)).
311
END PROCEDURE.
312

    
313
/*------------------------------------------------------------------------------
314
  3 and 4: B4 cancels the edit, B5 replaces the edit string with 999.  Logs the
315
  edited cell and its sum as the event sees them.
316
------------------------------------------------------------------------------*/
317
PROCEDURE sheet.F1Book.EndEdit:
318
   DEFINE INPUT-OUTPUT PARAMETER p-EditString AS CHARACTER NO-UNDO.
319
   DEFINE INPUT-OUTPUT PARAMETER p-Cancel     AS INTEGER   NO-UNDO.
320

    
321
   DEFINE VARIABLE iRow AS INTEGER NO-UNDO.
322
   DEFINE VARIABLE iCol AS INTEGER NO-UNDO.
323

    
324
   {&F1}:GetActiveCell(OUTPUT iRow, OUTPUT iCol) NO-ERROR.
325
   RUN log-line ("EndEdit " + CHR(64 + iCol) + STRING(iRow) + " | [" + p-EditString + "] | in event: "
326
                 + cell-value(iRow, iCol) + " || " + cell-value(iRow, 3)).
327

    
328
   IF iRow = 4 AND iCol = 2 THEN
329
   DO:
330
      p-Cancel = 1.
331
      RUN log-line ("3 EndEdit B4: Cancel = 1").
332
   END.
333
   ELSE IF iRow = 5 AND iCol = 2 THEN
334
   DO:
335
      p-EditString = "999".
336
      RUN log-line ("4 EndEdit B5: edit string set to [999]").
337
   END.
338
END PROCEDURE.
339

    
340
/*------------------------------------------------------------------------------
341
  6: logs every selection change; the first time B8 becomes active, writes B7
342
  and reads its sum in the same handler.
343
------------------------------------------------------------------------------*/
344
PROCEDURE sheet.F1Book.SelChange:
345
   DEFINE VARIABLE iRow AS INTEGER NO-UNDO.
346
   DEFINE VARIABLE iCol AS INTEGER NO-UNDO.
347
   DEFINE VARIABLE dSum AS DECIMAL NO-UNDO.
348

    
349
   {&F1}:GetActiveCell(OUTPUT iRow, OUTPUT iCol) NO-ERROR.
350
   RUN log-line ("SelChange " + CHR(64 + iCol) + STRING(iRow)).
351

    
352
   IF iRow = 8 AND iCol = 2 AND NOT lEventDone THEN
353
   DO:
354
      lEventDone = TRUE.
355
      {&F1}:EntryRC(7, 2) = "20".
356
      dSum = {&F1}:NumberRC(7, 3).
357
      RUN log-line ("6 SelChange: B7 = 20, then C7 | " + STRING(dSum) + " | expected 20").
358
      {&F1}:Recalc() NO-ERROR.
359
      dSum = {&F1}:NumberRC(7, 3).
360
      RUN log-line ("6 after Recalc, C7 | " + STRING(dSum) + " | expected 20").
361
   END.
362
END PROCEDURE.