Creating the UCase function

The UCase code is a bit more complicated. The main thing to remember is that strings from/to APW are always C-style strings (Pchar). If you want to use a function using pascal type strings, then you must convert from the C-style string first. You can not directly change the string passed from APW - this string is read-only.

Open the Unit1 code window.
First we need to declare our function. In the 'interface' section, after the line that declares the ReturnString function, add this line:

function UCase( StringIn : Pchar ) : Pchar; export; {$ifdef WIN32} stdcall ; {$endif}

Add this code in the 'implementation' section after the ReturnString function.

function UCase( StringIn : Pchar ) : Pchar;
{ NOTE: I haven't done any error checking - for string length, etc. }
var
   retstr : array[0..64] of char;
{ string to return to APW }
   instr, outstr : string[64];
{ some temp strings }
begin   

   
   instr := Strpas( StringIn );
{convert C string to pascal string;}
   
outstr := UpperCase( instr ); { do the function, using Delphi's built-in function}
   strplcopy( retstr , outstr , 60 );
{ convert pascal string to C string }
   Result := ReturnString( retstr );
{return string to APW }
end;

Before this function can be used in APW, it must first be declared as exported in the project file.
Click on the dlldemo tab at the bottom of the code window.

Add this line after the line exporting the Add function:

exports UCase;

This function is now complete. The next step is to test it.

on to: Testing the UCase function

back to: Creating the ReturnString function          Start