Copies specified number of characters to string.
function StrMove(Dest: PAnsiChar; const Source: PAnsiChar; Count: Cardinal): PAnsiChar; overload; function StrMove(Dest: PWideChar; const Source: PWideChar; Count: Cardinal): PWideChar; overload;
PAnsiChar StrMove(PAnsiChar Dest, const PAnsiChar Source, unsigned Count); PWideChar StrMove(PWideChar Dest, const PWideChar Source, unsigned Count);
StrMove copies exactly Count characters from Source to Dest and returns Dest. Source and Dest can overlap.
C++ Examples:
/* This example shows two functions that do the same thing as StrNew and StrDispose. */ char * AHeapaString(char *S) { // Allocate string on heap if ((S != NULL) && (S[0] != '\0')) { int L = StrLen(S) + 1; char *p = (char *)malloc(L); return StrMove(p, S, L); } return NULL; } void DisposeDaString(char *S) { // Dispose string on heap if (S != NULL) free(S); } void __fastcall TForm1::Button1Click(TObject *Sender) { char *S = "Now you see it."; char *otherS = AHeapaString(S); Canvas->TextOut(5, 10, otherS); Canvas->Refresh(); Sleep(5000); DisposeDaString(otherS); }
Delphi Examples:
{ This example shows two functions that do the same thing as StrNew and StrDispose. } function AHeapaString(S: PChar): PChar; { Allocate string on heap } var L: Cardinal; P: PChar; StrNew: PChar; begin StrNew := nil; if (S <> nil) and (S[0] <> #0) then begin L := StrLen(S) + 1; GetMem(P, L); StrNew := StrMove(P, S, L); end; Result := StrNew; end; procedure DisposeDaString(S: PChar); { Dispose string on heap } begin if S <> nil then FreeMem(S, StrLen(S) + 1); end; procedure TForm1.Button1Click(Sender: TObject); var S, otherS: PChar; begin S := 'Now you see it'; otherS := AHeapaString(S); Canvas.TextOut(5, 10, otherS); Canvas.Refresh; Sleep(5000); DisposeDaString(otherS); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|