Analysing the DataSource Structure

<< Click to Display Table of Contents >>

Navigation:  dycodoc Template Processing > Analysing and Modifying Templates by Code >

Analysing the DataSource Structure

Previous pageReturn to chapter overviewNext page

The following is a schematic overview, more detailed and complete source codes for C/C++, Visual Basic and Delphi are shipped with VPE.

The sample code demonstrates how to retrieve the complete data source structure from a template. In addition each field is set to the value "Hello World!".

Sample Code for the VPE Control

Dim tpl as TVPETemplatePage

Dim data_source As TVPEDataSource

Dim field As TVPEField

 

VPE.OpenDoc

tpl = VPE.LoadTemplate("\dycodoc\samples\sample2.tpl")

 

// In order to analyse the complete layout structure of a template, you

// need to iterate over each data source

For i = 0 To tpl.DataSourceCount - 1

 // Get the DataSource Object (i) from the template

 Set data_source = tpl.DataSourceObject(i)

 

 // Show how to retrieve the Prefix, FileName and Description

 prefix      = data_source.Prefix

 file_name   = data_source.FileName

 description = data_source.Description

 

 // Now iterate over all Field Objects in this DataSource

 For n = 0 To data_source.FieldCount - 1

         // Get the Field Object (n) from the DataSource

         Set field = data_source.FieldObject(n)

 

         // Show how to retrieve the field name and description

         field_name        = field.Name

         field_description = field.Description

 

         // Set the field to "Hello World!", except for the field

         // "Sender:Signature", because this is set to the file name

         // of the signature JPEG file

         If field.Name = "Sender:Signature" Then

                 field.AsString = "\dycodoc\samples\pakzadeh.jpg"

         Else

                 field.AsString = "Hello World!"

         End If

 Next n

Next i

 

// Dump the template and show the preview

VPE.DumpTemplate(tpl)

VPE.Preview

 

 

Sample Code for the VPE DLL (C/C++)

VpeHandle hDoc = VpeOpenDoc(hWnd, "Sample", 0);

VpeHandle hTpl = VpeLoadTemplate(hDoc, "\\dycodoc\\samples\\Sample2.tpl");

if (hTpl == NULL)

 return;         // an error had occurred, e.g. the file was not found

 

// In order to analyse the complete layout structure of a template, you

// need to iterate over each data source

for (i = 0; i < VpeGetTplDataSourceCount(hTpl); i++)

{

 char text[256];   // make sure the buffer is large enough...

 UINT size;

 

 // Get the DataSource Object (i) from the template

 VpeHandle hDataSource = VpeGetTplDataSourceObject(hTpl, i);

 

 // Show how to retrieve the Prefix, FileName and Description

 // Each time the information is copied to the string "text"

 size = sizeof(text);   // initalize "size"

 VpeGetDataSourcePrefix(hDataSource, text, &size);

 

 size = sizeof(text);   // reset "size", since it has been modified

                         // by the previous call

 VpeGetDataSourceFileName(hDataSource, text, &size);

 

 size = sizeof(text);   // reset "size"

 VpeGetDataSourceDescription(hDataSource, text, &size);

 

 // Now iterate over all Field Objects in this DataSource

 for (n = 0; n < VpeGetDataSourceFieldCount(hDataSource); n++)

 {

         // Get the Field Object (n) from the DataSource

         VpeHandle hField = VpeGetDataSourceFieldObject(hDataSource, n);

 

         // Show how to retrieve the description and the field name

         size = sizeof(text);   // reset "size"

         VpeGetFieldDescription(hField, n, text, &size);

 

         size = sizeof(text);   // reset "size"

         VpeGetFieldName(hField, n, text, &size);

 

         // Set the field to "Hello World!", except for the field

         // "Sender:Signature", because this is set to the file name

         // of the signature JPEG file

         if (stricmp(text, "Sender:Signature" == 0)

                 VpeSetFieldAsString(hField, "\\dycodoc\\samples\\pakzadeh.jpg");

         else

                 VpeSetFieldAsString(hField, "Hello World!");

 }

}

 

// Dump the template and show the preview

VpeDumpTemplate(hDoc, hTpl);

VpePreviewDoc(hDoc, NULL, VPE_SHOW_NORMAL);