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 TCtResource.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 TCtResource method:
procedure TCtResource.Add(data : pointer; size : integer); virtual;
data is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type. size indicates 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 with the TCtResource.Number property 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
procedure AddMyResource(hTable : TCtTable);
var
hRes : TCtResource;
str : string;
begin
Writeln('Adding my resources to table ', hTable.Table);
str := 'this is my resource data';
hRes := TCtResource.Create(hTable, $10001, CTDB_ASSIGN_RESOURCE_NUMBER, 'MyResource');
try
// add the resource
hRes.Add(pointer(pchar(str)), Length(str) + 1);
except
on err: ECtError do Writeln('Error ', err.Message);
end;
hRes.Free;
end;