Length of a declared pChar Constant.. 
Author Message
 Length of a declared pChar Constant..


Quote:
>Does anyone know of a simple way to declare a null terminated string
>constant which exceeds the 256 char line limit of Turbo Pascal/Windows?

>ie, I want to define messages in in my code which are greater than 256
>characters.  However, using the code below is truncates the
>string.  My normal work around is to read the messages in from an
>external file at run time, or to concatinate short messages into longer
>ones.  Isn't there an easier way?

>const
>  Message1:pChar='This message is'+
>                 'Truncated to 256 characters..';
> or
>  Message2:Array[0..1024]='This one also gets truncated';

>-Ed

I have a program with 38 KB of PChars in an .obj file that I link in
at run-time.  There are about 250 PChars in the file, with the shortest
being about 100 chars and the longest being about 1700.  

What I do is:
1.)  Type the PChars into a plain text file in the format:

FirstConstantName
Actual text for the PChar.

SecondConstantName
Text for the Second PChar.

2.) Process the text file with a little program that produces two
    new files:
    - A binary file with the PChars laid end to end.

    - a text file listing ...
       const
          FirstConstantName = 0;
          SecondConstantName = L1 + 1;
          ThirdConstantName  = L1 + L2 + 2;
          N_th__Name         = L1 + L2 + .... + L(N-1) + (N-1);  

      ie.,  The value of each constant is the location within
            the binary file of the first byte of each PChar.

3.) Use {$I ConstantFileName} to include the file of constants into
    a little unit ...

4.) Process the binary file with BinObj and use {$L ObjFileName} to
    link it into the unit.

5.) Put one little procedure into the unit to return a PChar when
    you pass it one of the constant names.

Unit uPChar;

uses Strings;

Interface

{$I PChars.Con}

function GetPChar(PCharName: Word): PChar;

Implementation

procedure PCharBlock; external; {$L PChars.Obj}

function GetPChar(PCharName: Word): PChar;
var P: Pointer;
begin

  GetPChar := StrNew(P);  
end;

end.

That is the simple version of it.  In practice, my PChars have special
formatting chars in them (for line breaks, tabs, indents, colour changes,
centering, etc.) and I have a descendant of TurboVisions TStaticText
that I use to display the PChars.

Originally I just put the PChars into a Tcollection, wrote the collection
to a stream, linked the stream into the a unit used by the main program ....  
but eventually the program got so large and I needed ways to reduce size
so I went with the technique I outlined above.



Wed, 18 Jun 1902 08:00:00 GMT  
 Length of a declared pChar Constant..

Does anyone know of a simple way to declare a null terminated string
constant which exceeds the 256 char line limit of Turbo Pascal/Windows?

ie, I want to define messages in in my code which are greater than 256
characters.  However, using the code below is truncates the
string.  My normal work around is to read the messages in from an
external file at run time, or to concatinate short messages into longer
ones.  Isn't there an easier way?

const
  Message1:pChar='This message is'+
                 'Truncated to 256 characters..';
 or
  Message2:Array[0..1024]='This one also gets truncated';

-Ed



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How do you declare a constant set?

2. Declaring constants

3. Should BP allow pChar := constant

4. pchar := string; string:=pchar

5. Conversion of Pascal Real constants to C/C++ float constants

6. datacombobox not saving all the character even though it is within length of field length

7. How to declare dynamic array in fpc ??

8. Declared variables

9. Declare interrupt procedures in Object

10. DBText.Caption not declared???

11. How to declare an Array with alphabets insteads of numbers

12. declaring a string....

 

 
Powered by phpBB® Forum Software