Need help porting function to Free Pascal 
Author Message
 Need help porting function to Free Pascal


> know that the Mem[] is referencing Real-Mode memory, but i want it to
> reference the variable I am trying to reference with Seg(),Ofs() (which
> of course don't work with FPC).

> function Stz(var Start;  max:Byte):String;
> var I : Byte;
>     S : String;
>     C : Char;
> begin
>   If Max<1 then Max := 1;
>   Dec(Max,1);
>   S := '';
>   I := 0;
>   repeat
>       C := Chr(Mem[Seg(Start):Ofs(Start)+I]);
>       If (C<>#0) and (C<>#26) then S := S + C;
>       Inc(I);
>   until ((C = #0) or (C = #26)) or (Length(S)>Max);
>   Stz := S;
> end;

> I know it could be written better (not using repeat..until, etc) but I'll
> get around to that later (unless someone wants to optimize it or something).

Use PChar instead (also better in TP, much faster than your mem
construct)... I'd do something like

Function Stz(var Start; max: Byte): String;
Var I: Byte;
    P: PChar;
  If Max < 1 Then Max := 1;
  Stz := '';
  I := 0;

  While Not(P[I] in [#0,#26]) And (Length(Stz) < Max) Do
      Stz := Stz + P[I];

Some remarks:

a) this is written for FPC, it won't work in TP (you'll have to use a
temporary string, like you did first)
b) my version will continue at most until Length(S) = Max, yours will
continue until Length(S) = Max + 1, I don't know whether this was
intended or not
c) it may contain bugs (I've tested whether it compiles, but not the


Sat, 14 Jul 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Need help porting function to Free Pascal

2. Need help porting ancient MS-DOS Pascal program to Linux

3. Need help from "Free Pascal" users

4. free idsoftware front-end program in pascal--need help - idgames.pas [1/1]

5. free idsoftware front-end program in pascal--need help - idgames.pas [1/1]

6. free pascal and serial ports under linux

7. Converting Pascal PORT function to C++

8. Need help with recursive functions in Turbo Pascal 7.0

9. Need help with a pascal function

10. Help With Pascal Iwant to call C function from Pascal

11. Need help with getting data from parallel port


Powered by phpBB® Forum Software