March 2000
Intermediate to advanced
576 pages
18h 13m
English
SetString Procedure
procedure SetString(var Str: string; Buffer: PChar; Length: Integer);
The SetString procedure sets the length of
Str to Length, then copies
Length characters from Buffer
to the string. SetString is not a real
procedure.
If Str is a long string,
SetString always allocates a new string, so
Str is set to a unique string.
Str can be a ShortString, in
which case the Length must be less than 256.
Buffer can be nil, in which
case the string length is set, but its contents are left
uninitialized. In the case of a ShortString, the
previous string contents are left untouched.
// Given an instance or module handle, return the corresponding
// filename. Note that Delphi will automatically convert
// a PChar to a string, but it must scan the PChar to learn
// its length. GetModuleFileName returns the length, so there is
// no need to let Delphi rescan the string.
function GetModuleName(Instance: THandle): string;
var
Len: Integer;
Buffer: array[0..MAX_PATH] of Char;
begin
Len := GetModuleFileName(HInstance, Buffer, SizeOf(Buffer));
SetString(Result, Buffer, Len);
end;| AnsiString Type, SetLength Procedure, ShortString Type, String Keyword, WideString Type |
Read now
Unlock full access