A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

StuffString for KOL


You can cut and paste Move() and StuffString() functions out of FreePascal source code (sysutils and strutils) and paste them into your unit.

Here is the download link for an example unit showing stuffstring in use: StuffString Example

When calling on this function without cutting and pasting it into your unit, it will bring in 50K and it will conflict with freepascal's windows.pas (since sysutils relies on windows.pas out of freepascsal, and KOL relies on windows.pas out of ppDelphi.zip or Thaddy's package).

If you cut and paste it directly into your unit, it will only cause about 3K to the exe.

The initialization/finalization must cause the 50K in the exe, or other things.. so use StuffString directly by cutting and pasting it into a unit of your own.

Further optimizations with StuffString for KOL may be to use one of FASTCODE's "move" functions. It can be downloaded and seen here: FastCode Move Challenge You'll probably want one of the Pascal versions of fastcode if freepascal doesn't compile the assembly versions easily.


Example:
Paste this into your code to have access to a stuffstring function when using in KOL.
Call it Move2 and stuffstring2 just to avoid conflicts with move from kol.pas

(rename to move2, or myMove to aviod conflict if you wish)
procedure Move(const source;var dest;count:SizeInt);
type
  bytearray    = array [0..high(sizeint)-1] of byte;
var
  i:longint;
begin
  if count <= 0 then exit;
  Dec(count);
  if @source<@dest then
    begin
      for i:=count downto 0 do
        bytearray(dest)[i]:=bytearray(source)[i];
    end
  else
    begin
      for i:=0 to count do
        bytearray(dest)[i]:=bytearray(source)[i];
    end;
end;

(rename to StuffStr, or StuffString2 to avoid conflict if you wish)
Function StuffString(const AText: string; 
                     AStart, ALength: Cardinal;  
                     const ASubText: string): string;
var
 i,j : longint;
begin
 j:=length(ASubText);
 i:=length(AText);
 SetLength(Result, i - ALength + j);
 move2 (AText[1],result[1],AStart - 1);
 move2 (ASubText[1],result[AStart], j);
 move2 (AText[AStart+ALength], Result[AStart+j],i -AStart - ALength + 1);
end;


About
This site is about programming and other things.
_ _ _