Grids and Rows

<< Click to Display Table of Contents >>

Navigation:  Programming > Property Grids >

Grids and Rows

 

PropertyGrids and -Rows can be combined:

 

propertygridandrow

 

This grid can be created with rather compact code:

 

var  norm, bold : Integer;

begin

   WPRichText1.Clear;

   WPRichText1.ProtectedProp := [ppParProtected];

 

   WPRichText1.AttrHelper.Clear;

   WPRichText1.AttrHelper.SetFontName('Tahoma');

  norm := WPRichText1.AttrHelper.CharAttr;

 

   WPRichText1.AttrHelper.Clear;

   WPRichText1.AttrHelper.SetFontName('Tahoma');

   WPRichText1.AttrHelper.SetCharStyles(WPSTY_BOLD,WPSTY_BOLD);

  bold := WPRichText1.AttrHelper.CharAttr;

 

   WPRichText1.ActiveParagraph.AppendPropertyGrid(

           wpLevelUp, 'Address','', [wpapShaded])

    .AppendPropertyGrid(wpNested, 'Name', 'address.name')

            .IsParProtected(0)

            .Append('Julian ',norm)

            .Append('Ziersch ',bold)

    .AppendPropertyGrid(wpSameLevel, 'Str', 'address.str')

            .IsParProtected(0)

    .AppendPropertyGrid(wpSameLevel, 'City', 'address.city')

            .IsParProtected(0)

  .AppendPropertyGrid(wpLevelUp, 'Contact','', [wpapShaded])

    .AppendPropertyGrid(wpNested, 'Telefone')

      .AppendPropertyRow('private','tel.private' )

              .IsParProtected(0)

      .AppendPropertyRow('mobile','tel.mobile' )

              .IsParProtected(0)

              .SetText('123456789')

    .AppendPropertyGrid(wpSameLevel, 'E-Mail')

      .AppendPropertyRow('private','email.private' )

              .IsParProtected(0)

      .AppendPropertyRow('business','email.business' )

              .IsParProtected(0);

end;

 

 

In the code above first two character attribute index values are initialized: norm and bold. They are used later to insert formatted text.

 

Then AppendPropertyGrid is called to create the first grid. The function returns a reference to the last cell, the data cell. It can be used to create other grids, nested or under  the current. The result value can also be used to call AppendPropertyRow.

 

All used functions return a reference to a TParagraph and can so be used in a chain, only separated by ".", i.e. TParagraph.Append not only adds text to a paragraph but also returns a reference to that paragraph to be used in another call.

IsProtected(0) disables the protection.

 

 

How can the values be read?

 

The easiest is to call FindCell:

 

 ShowMessage(WPRichText1.FindCell('address.name').Text);

 ShowMessage(WPRichText1.FindCell('tel.mobile').Text);

 

To read more properties at once we recommend to create a par-next loop:

 

var par : TParagraph;

begin

par := WPRichText1.FirstPar;

while par<>nil do

begin

  // We only check table cells:

  if (par.ParagraphType=wpIsSTDPar) and par.HasProp(paprIsTable) then

  begin

    if Copy(par.Name,1,4)='tel.' then

          ShowMessage(par.Name + '=' + par.Text);

  end;

  par := par.Next;

end;

end;