SetMem Function

Action

Copies a specified number of bytes at a specified position into a string.

Include file

Kernel.bdh

Syntax

SetMem( inout sDest     : string,
        in    nPosition : number,
        in    sSource   : string,
        in    nLen      : number optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
sDest Identifies the destination string.
nPosition Specifies the position where to copy into sDest, where the first position in a string is 1 (not 0)
sSource Identifies the string to copy
nLen Length to copy (optional).

Example

dcltrans
  transaction TSetMem
  const
    SIZE_STRUCT := 32; // hexadecimal notation
    CONST_VAL   := "\hAF0034F5FF01";// of 6 bytes
  var
    myBDLstring : string(SIZE_STRUCT);
    bOk         : boolean;
  begin
    // Copy sizeof(CONST_VAL) bytes = 6 from CONST_VAL
    // into myBDLstring starting at position 2 and thereby
    // (through mapping) set the elements myShort and myLong
    // in Struct1
    bOk := SetMem(myBDLstring, 2, CONST_VAL);
    if bOk then
      write("myShort and myLong successfully set");writeln;
    else
      write("error setting myShort and myLong"); writeln;
    end;
  end TSetMem;

Output

myShort and myLong successfully set