When adding a Resource to a table, a special variable-length record is written to the table, containing the information from the Resource Data Block. This is done even if a data file uses fixed-length records. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by c-tree Plus during the call to CTResource::Add() method. In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.
The following steps are required to add a new resource to a table:
To add a new resource you must call the following CTResource class method:
void CTResource::Add(pVOID data, VRLEN size);
data is any collection of data that you wish to store as a Resource. This can be a character string, a structure, or any variable type. size indicate the number of bytes occupied by data parameter value.
The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use. If the Resource Number is a value of CTDB_ASSIGN_RESOURCE_NUMBER (0xffffffff), c-tree Plus assigns this Resource the next available Resource Number for this Resource Type in the specified data file. The assigned number can be retrieved by calling CTResource::GetNumber() method before the resource object is destroyed. The Resource Name is optional. c-tree Plus does not guarantee unique Resource Names. Names starting with the character sequence "FC!" or "RD!", are reserved for FairCom use.
Example
void AddMyResource(const CTTable& hTable, ULONG type, const CTString& name, pVOID data, VRLEN size)
{
CTResource* hRes = new CTResource(hTable, type, CTDB_ASSIGN_RESOURCE_NUMBER, name);
try
{
hRes->Add(data, size)
printf("Resource added with number %u\n", hRes->GetNumber());
}
catch (CTException &err)
{
printf("Error %d - %s\n", err.GetErrorCode(), err.GetErrorMsg());
}
delete hRes;
}