contents   index   previous   next



BStrReAlloc

 

f90VB Modules

 

f90VBDefs, f90VBBStrings

Summary

 

Subroutine BStrReAlloc changes the content of a BString to the content passed in StrSrc. BStrReAlloc can also be used to create a new BString, if the handle passed in StrDest is null.

Syntax

 

subroutine BStrReAlloc (Str, StrSrc, iRet, StrLen

integer(BSTRHNDL_KIND),intent(inout):: Str
{
character(len=*),intent(in):: StrSrc |
integer(OLECHAR_KIND),dimension(:),intent(in):: StrSrc |
type(OLESTRING),intent(in):: StrSrc |
integer(BSTRHNDL_KIND),intent(in):: StrSrc
}
integer(HRESULT_KIND),intent(out),optional:: iRet
integer(LONG_KIND),intent(in),optional:: StrLen

Arguments

 

Str [Input/Output]

Handle of String to be reallocated.

 

StrSrc [Input]

String with the new content to store in StrDest. StrSrc can be any of the f90VB string types (Fortran Strings, Fixed OLE Strings, Fortran OLE Strings or BStrings).

iRet [Output, Optional]

Upon return, iRet contains the number of characters copied to Str, or BSTRINGS_ERROR if the procedure failed.

 

StrLen [Input, Optional]

Number of characters from StrSrc that should be copied to Str. If StrLen>StrLenTrim(StrSrc), then Str's buffer is allocated to the size indicated in StrLen, and all characters in StrSrc are copied to Str. If StrLen is not passed, BStrReAlloc assumes its value is the same as the trimmed length of StrSrc.

Comments

 

Subroutine BStrReAlloc is used to change the contents of existing BStrings. If Str is a handle to an existing BString, BStrReAlloc will take care of reallocating the BString, if necessary, to ensure it can hold the new content. If Str is a null handle, then BStrReAlloc will allocate a new BString and initialize its content to the passed StrSrc.

 

BStrReAlloc always uses the default code page and conversion flag values when StrSrc is a Fortran String. If you want to create a BString with user-specified code page and flags, you can use the more general procedure StrCopy.

 

To restore the memory used by a BString created with BStrReAlloc, the calling program must explicitly deallocate the string using subroutine StrFree.

Argument StrLen

 

Argument StrLen is used to indicate how many of the characters in StrSrc should be copied to Str. If zero is passed in argument StrLen, BStrReAlloc reallocates Str and sets its content to null (an empty string). If argument StrLen is not passed or has a negative value, the Str buffer is reallocated to, at least, the size of StrLenTrim(StrSrc).

Examples

 

Program BStrReAllocExamples

 

!Demonstrates the use of function BStrReAlloc

!Copyright 1999-2000, Canaima Software

!All rights reserved

 

!load f90VB modules

use f90VBDefs

use f90vbBStrings

implicit none

 

!declare two BStrings

integer(BSTRHNDL_KIND):: BStrA, BStrB

integer(HRESULT_KIND)::iRet

character(len=50)::Fstr

 

!Allocate and initialize BStrA

BStrA = BStrAlloc('Example string')

 

!Allocate and initialize BStrB with the first

!seven characters from BStrA

BstrB= BStrAlloc(BstrA,7)

 

!print BStrings

call StrCopy(BstrA,FStr)

print *,'BStrA:', trim(FStr)

print *,'BString A Length:',StrLenTrim(BStrA)

 

call StrCopy(BstrB,FStr)

print *,'BStrB:', trim(FStr)

print *,'BString B Length:',StrLenTrim(BStrB)

 

!Change content in BStrA

call BStrReAlloc(BStrA,BStrB,iRet)

 

call StrCopy(BStrA,FStr)

print *,'BStrA:', trim(FStr)

print *,'BString A Length:',StrLenTrim(BStrA)

 

!Free string memory

call StrFree(BStrA)

call StrFree(BStrB)

 

stop

end

Related Topics

 

For information about See
Creating new BStrings BStrAlloc
Changing the content of a BString StrCopy
Freeing dynamic strings memory StrFree

 


OLEStrAlloc