[comp.lang.modula2] programming for MSWindows in JPI Modula 2. An alternative to C?

peter@cs.umu.se (Peter Lundberg) (08/31/90)

When Topspeed announced that their their V2.0 would have an interface
towards MS-windows I became wery interested....

This is because I have about two years of work in a program based on
their version 1.14. In this program there is  "a whole lot of shaking
going on" in terms of fonts, menus, printing graphics to different kinds
of printers and so on.

At first I used a Swedish Graphics library, but it became to large and
to slow so I had to build THE WHOLE #### myself.

So naturally, porting approx. 20 000 odd lines to MSWindows is to me a
wery good idea. I have all the "parts", the MS-WIN toolkit, JPI techkit,
MS-C 5.1 and so on. I also have a very strong aversion against working
with C, so everything should be just fine.

But it isn't, the problem is twofold, 1) the Microsoft examples work and
their documentation is correkt, the JPI ditto don't and isn't.
2) the things that I have mananged to get up and running is so very good,
the possibilities of memory handling that Windows offers is just great,
and (for example) sending graphics to a printer (no matter what kind)
is like stealing candy from babies.

Do You see my problem? I'm hesitating in front of a rather big step,
not beeing relly sure if I can trust this product or not. I would wery much
like to but if I (in a year from now) would find out that this stuff
doesn't work after all I would simply be broke!

Therefore; I would like to establish a mailing-list about experiences
with Topspeed M2, C and MS-Windows. There must be a lot of people out
there, in exactly the same position as myself, together we should be able
to work things out much faster.

For example:
- What really does  Windows.EntryPoint do?
- Whatever it does, is it impossible to have multiple instances
  running in TP M2?
- Would it be possible to use Topspeed C to do the (main) part of the
  interface with Windows and do the rest interfacing Topspeed C and M2?
- Would this be any better?
- WHO WROTE PAGE 45 - 50 IN THE TECH-KIT MANUAL!!!!!!
- Is there anyone who knows how to make the M2 compiler produce code
  that is "codeview-compatible", and who got cvw working properly?
- Just producing a .PRJ file that lets me import my own modules has been
  a problem. This one does, but produces 100 warnings, any better ideas?
  OBS. that %o%m_mlib must be last on the line to make it work.

make Win EXE
option -case +map +pack +check -vid +windows +manual
model Small
export %N
include initmwin winfloat
import rs_mwlib windows win87em %o%m_mlib

Debugger or not, debugging these applications is not an easy task, so iv'e
decided to contribute with a small procdure that can write a string of
text directly to a color/mono monitor FROM ANYWHERE WITHIN a running
application. It has been rather useful to me, I hope it vill be the same
for You.

MODULE Direct;

IMPORT Str,Lib;

(* export's *)

TYPE WhatToDoType = (ClearLine,ClearAll,ClearRect,NoClear,Auto);

VAR Screen [0B000H:0] : ARRAY [1..25] OF ARRAY [1..80] OF RECORD
         (*[0B800H:0] mono to color *)                       Tkn  : CHAR;
                                                             Attr : SHORTCARD;
                                                           END;
    AutoLineCountVar : CARDINAL;
    ALERT            : BOOLEAN;
    NOALERT          : BOOLEAN;

    i                : CARDINAL;

PROCEDURE PutOnOtherScreen (S: ARRAY OF CHAR; What : WhatToDoType;
                      X1,Y1,X2,Y2,Delay : CARDINAL; Alert : BOOLEAN);

VAR i : CARDINAL;

    PROCEDURE ClrLine (X1,X2,Y: CARDINAL);
    VAR i : CARDINAL;
    BEGIN
      FOR  i := X1 TO X2 DO
        Screen [Y][i].Tkn := ' ';
        Lib.Delay (1);
      END;
    END ClrLine;

    PROCEDURE WrLine (S : ARRAY OF CHAR; X1,Y: CARDINAL);
    VAR i : CARDINAL;
    BEGIN
      FOR  i := 0 TO  + Str.Length (S) DO
        Screen [Y][X1+i].Tkn := S[i]; 
      END; 
    END WrLine; 
 
BEGIN 
  IF Alert THEN 
    Lib.Sound (500); Lib.Delay (100);  Lib.Sound (1000); 
    Lib.Delay (100); Lib.Sound (1500); Lib.Delay (100); 
    Lib.NoSound; 
  END; 
  Lib.Delay (Delay * 1000); 
  IF What <>  NoClear THEN  (* nagonting skall tommas *) 
    CASE What OF 
      ClearLine : ClrLine (1,80,Y1); 
                  WrLine  (S,X1,Y1); | 
      Auto      : INC (AutoLineCountVar,1); 
                  IF AutoLineCountVar > 25 THEN 
                    AutoLineCountVar := 1; 
                  END; 
                  IF AutoLineCountVar = 1 THEN 
                    FOR i := 1 TO 25 DO 
                      ClrLine (1,80,i); 
                    END; 
                  END; 
                  ClrLine (1,80,AutoLineCountVar); 
                  WrLine  (S,1,AutoLineCountVar); | 
      ClearAll  : FOR i := 1 TO 25 DO 
                    ClrLine (1,80,i); 
                  END; 
                  WrLine  (S,1,Y1); | 
      ClearRect : FOR i := Y1 TO Y2 DO 
                    ClrLine (X1,2,i); 
                  END; 
                  WrLine  (S,X1,Y1); | 
    END; (* Case *) 
  END;  (* if *) 
END PutOnOtherScreen; 
 
BEGIN
  AutoLineCountVar := 0; (* init *) 
  ALERT := TRUE; 
  NOALERT := FALSE; 
 
  PutOnOtherScreen ('This is an example',ClearAll,1,5,0,0,1,ALERT); 
  FOR i := 1 TO 50 DO 
   IF ODD(i) THEN 
     PutOnOtherScreen ('This is an other example',Auto,0,0,0,0,0,ALERT); 
   ELSE 
     PutOnOtherScreen ('A silent third example',Auto,0,0,0,0,0,NOALERT); 
   END; 
  END; 
END Direct.


To sum it all up; Topspeed is one great compiler, the documentation is
miserable. Could possibly a few of us together do something about it?

Comments and suggestions to:
peter@cs.umu.se

Peter Lundberg
Ume{ Sweden