PROCEDURE TForm4.TestShlWAPIStrTrim(Sender : TObject);
VAR strtotrim : STRING;
VAR strtotrimlen : INTEGER;
VAR strtotrimbufp : POINTER;
VAR charstotrim : STRING;
VAR apiretval : BOOL;
VAR newinfoline : STRING;
BEGIN
strtotrim := '';
strtotrimlen := 0;
strtotrimbufp := NIL;
charstotrim := '';
apiretval := FALSE;
newinfoline := '';
//BEGIN The following code will cause an EAccessViolotion exception
//strtotrim := ' ' + #9 + ' The quick, brown fox jumped over the fence ' + #9 + #13 + #10;
//charstotrim := ' ' + #9 + #10 + #13 + ' ';
//newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
//+ charstotrim;
//Memo1.Lines.Add(newinfoline);
//This code will cause an EAccessViolotion exception in the following line !!!
//apiretval := StrTrim(PChar(strtotrim), PChar(charstotrim));
//IF apiretval = TRUE THEN
//newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"'
//ELSE
//newinfoline := 'StrTrim returned FALSE !';
//Memo1.Lines.Add(newinfoline);
//END The following code will cause an EAccessViolotion
strtotrim := ' The quick, brown fox jumped over the fence ';
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := ' ';//Remove blanks
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (blanks)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := ' ' + #9 + ' The quick, brown fox jumped over the fence ' + #9 + #13 + #10;
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := ' ' + #9 + #10 + #13 + ' ';
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (blanks, tabs, carriage returns, and line feeds)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := ' ' + #9 + 'AA The quick, brown fox jumped over the fence BB' + #9 + #13 + #10;
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := ' ' + #9 + #10 + #13 + 'AB';
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (blanks, tabs, carriage returns, line feeds, A, and B)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := 'AA The quick, brown fox jumped over the fence BB ';
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := 'aB';
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (a and B)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := 'AA The quick, brown fox jumped over the fence BB ';
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := 'Ab';
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (A and b)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := 'The quick, brown fox jumped over the fence'; //Nothing to delete !
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := ' ' + #9 + #10 + #13 + 'AB';
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (blanks, tabs, carriage returns, line feeds, A, and B)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := ' ' + #9 + 'AA The quick, brown fox jumped over the fence BB' + #9 + #13 + #10;
strtotrimlen := Length(strtotrim);
strtotrimbufp := AllocMem(strtotrimlen + 1);
Move(strtotrim[1], strtotrimbufp^, strtotrimlen);
charstotrim := '';//No characters to delete specified
newinfoline := 'StrTrim called with psz (without the quotation marks) = "' + strtotrim + '", pszTrimChars = '
+ '"' + charstotrim + '" (No characters to delete specified !)';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, PChar(charstotrim));
IF apiretval = TRUE THEN
BEGIN
strtotrim := PChar(strtotrimbufp);
newinfoline := 'StrTrim returned TRUE and "' + strtotrim + '"';
END
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
FreeMem(strtotrimbufp);
strtotrim := ''; //Empty string
strtotrimbufp := NIL;
newinfoline := 'StrTrim called with psz = NIL, pszTrimChars = NIL';
Memo1.Lines.Add(newinfoline);
apiretval := StrTrim(strtotrimbufp, NIL);
IF apiretval = TRUE THEN
newinfoline := 'StrTrim returned TRUE'
ELSE
newinfoline := 'StrTrim returned FALSE !';
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END; |
StrTrim called with psz (without the quotation marks) =
" The quick, brown fox jumped over the fence ", pszTrimChars = " " (blanks)
StrTrim returned TRUE and "The quick, brown fox jumped over the fence"
StrTrim called with psz (without the quotation marks) =
" The quick, brown fox jumped over the fence
", pszTrimChars = "
" (blanks, tabs, carriage returns, and line feeds)
StrTrim returned TRUE and "The quick, brown fox jumped over the fence"
StrTrim called with psz (without the quotation marks) =
" AA The quick, brown fox jumped over the fence BB
", pszTrimChars = "
AB" (blanks, tabs, carriage returns, line feeds, A, and B)
StrTrim returned TRUE and "The quick, brown fox jumped over the fence"
StrTrim called with psz (without the quotation marks) =
"AA The quick, brown fox jumped over the fence BB ", pszTrimChars = "aB" (a and B)
StrTrim returned FALSE !
StrTrim called with psz (without the quotation marks) =
"AA The quick, brown fox jumped over the fence BB ", pszTrimChars = "Ab" (A and b)
StrTrim returned TRUE and " The quick, brown fox jumped over the fence BB "
StrTrim called with psz (without the quotation marks) =
"The quick, brown fox jumped over the fence", pszTrimChars = "
AB" (blanks, tabs, carriage returns, line feeds, A, and B)
StrTrim returned FALSE !
StrTrim called with psz (without the quotation marks) =
" AA The quick, brown fox jumped over the fence BB
", pszTrimChars = "" (No characters to delete specified !)
StrTrim returned FALSE !
StrTrim called with psz = NIL, pszTrimChars = NIL
StrTrim returned FALSE ! |