Author Topic: Look at this before you compile your old code with PB 9  (Read 3933 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 918
    • it-berater
Look at this before you compile your old code with PB 9
« on: August 15, 2008, 10:20:57 PM »
Today I got to compile my first program with the new PowerBASIC for Objects 9.

It was not designed for the new compiler, it was just a big project made on PB 8.

Soon i realized, that i had to make some changes or else this project would not be compiled on the new PB 9.

1. First I had several Labels and MACRO Names (ME, ISWIN etc.) which are now reserved words.
These had to be changed.

Example:
Code: [Select]
MACRO FUNCTION ISWIN(P1) = (IsWindow(P1)<>0) 
Is now a reserved word. But as it seems to do just the same, as my MACRO before. So I just aded a comment.

2. I had this inside a Function
Code: [Select]
%X_CT_PROCESS_TERMINATE = &H1 

This was Ok in PB 8.04. Actually this is not more valid. It says "Must be outside SUB/FUNCTION/CLASS".

In fact these Compiler-variables have never been local therefore this is rather a clarification, not  really a disadavantage at this place. It can just be move a few lines up.

At another place this is a bigger problem.

I had a include file, which was called "MAININCLUDE" which contained several initializations and was called at the start of WINMAIN.
Also I had an Inlcude File called "Exitinclude" which was called at the End of WINMAIN.

These contain a lot fo things like this:

Something like this:
 
Code: [Select]
#IF NOT %DEF(%A_Mainincludes_INC)
 %A_Mainincludes_INC=1 '<----- This Line is now invalid because it was in WINMAIN
'------------------------------------------------------------------------------------------------
   ' Mainincludes aus 009_WRS_ST.inc
   #IF %DEF(%WRS_Maininclude)
    DIM WI(%WR_ST)
   #ENDIF   

Now the second line becomes invalid. To keep it working i will need to change the whole code to use the

Code: [Select]
#INCLUDE ONCE
statement because this include file was protected from beeing multiple time inserted using the

Code: [Select]
%A_Mainincludes_INC=1
and this is not more going to work inside WINMAIN.

Therefore the #INCLUDE ONCE was really needed after this change. For new programms the new statement makes things easier.

Thinking a Moment on it, I believe that for me the ONCE is the normal State and to include something multiple times is rather seldom. Therefore I used a Replace Utility which replaced all "'INCLUDE "" with #INCLUDE ONCE "".

This was surprisingly one of a few things i needed to change to make it compile.

Also i can say that in terms of compiling speed it seemed to be as fast as PB 8.04 - not slower.
I wondered because we have one more Pass now (thats why we do not need declares anymore).


« Last Edit: August 15, 2008, 10:27:34 PM by Theo Gottwald »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
Re: Look at this before you compile your old code with PB 9
« Reply #1 on: August 15, 2008, 10:37:01 PM »
Quote
Now the second line becomes invalid.

The second line doesn't become invalid. Just move the include outside WinMain. Constants aren't allowed to be declared inside a function, and including that file in WinMain, you are declaring the %A_Mainincludes_INC inside a function.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 918
    • it-berater
Re: Look at this before you compile your old code with PB 9
« Reply #2 on: August 16, 2008, 07:00:12 AM »
The Include was Designed as a Collection of statements, which were to be inserted at the start of any WINMAIN.
Thats why they have been called "MAININCLUDE.inc".
This is just how an Initialization in an Object.
It still works, just had to use #INCLUDE ONCE instead of the other mechanism.
I have already solved the problem, however this code will never compile under PB 8.0x anymore.