Copies up to a specified maximum number of characters from Source to Dest.
function StrLCopy(Dest: PAnsiChar; const Source: PAnsiChar; MaxLen: Cardinal): PAnsiChar; overload; function StrLCopy(Dest: PWideChar; const Source: PWideChar; MaxLen: Cardinal): PWideChar; overload;
PAnsiChar StrLCopy(PAnsiChar Dest, const PAnsiChar Source, unsigned MaxLen); PWideChar StrLCopy(PWideChar Dest, const PWideChar Source, unsigned MaxLen);
StrLCopy copies at most MaxLen characters from Source to Dest, then adds a null terminator to Dest and returns Dest. The SizeOf standard function (Delphi) or the sizeof operator (C++) can be used to determine the MaxLen parameter. Usually MaxLen equals SizeOf(Dest)-1.
C++ Examples:
/* The following example uses an edit control and a button on a form. When the button is clicked, the first X bytes of the edit control are copied into a buffer, where X is a predefined number. */ const MAX_BUFFER = 10; void __fastcall TForm1::Button1Click(TObject *Sender) { char szBuffer[MAX_BUFFER+1]; StrLCopy(szBuffer, Edit1->Text.t_str(), MAX_BUFFER); Application->MessageBox(WideString(szBuffer).c_bstr(), L"StrLCopy example", MB_OKCANCEL); }
Delphi Examples:
{ The following example uses an edit control and a button on a form. When the button is clicked, the first X bytes of the edit control are copied into a buffer, where X is a predefined number. } const MAX_BUFFER = 10; procedure TForm1.Button1Click(Sender: TObject); var Buffer: array [0..MAX_BUFFER] of char; begin StrLCopy(Buffer, PChar(Edit1.Text), MAX_BUFFER); Application.MessageBox(Buffer, 'StrLCopy example', MB_OKCANCEL); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|