logo
down
shadow

How can I save a TTreeview to Windows and keep its hierarchical structure?


How can I save a TTreeview to Windows and keep its hierarchical structure?

By : user2950387
Date : November 17 2020, 11:55 AM
hope this fix your issue The answer as pointed out by 500 - Internal Server Error was to change the path I was passing to the recursive procedure.
Also I had to get the path of the node in a string format, and then use that as the new path:
code :
function NodeToStringPath(Node: TTreeNode; var Path: string): string;
begin
  Result := '';

  Path := Node.Text + '\' + Path;
  if Node.Level = 0 then
  begin
    Result := Path
  end
  else
    Result := NodeToStringPath(Node.Parent, Path);
end;

function RemoveLastFolder(var S: string): string;
begin
  Result := '';

  repeat
    Delete(S, Length(S), 1)
  until
    (S[Length(S)] = '\') or (S = '');

  Result := S;
end;

procedure SaveTreeViewStructure(TreeView: TTreeView; const OutDirectory: string);
var
  RootDir, SubDir: string;
  Node: TTreeNode;

  // the recursive procedure
  procedure SaveNode(Node: TTreeNode);
  var
    sPath: string;
    Obj: TObject;
    Child: TTreeNode;
  begin
    Obj := TObject(Node.Data);

    // node type is a folder/parent, so create the folder in windows...
    if Obj.ClassType = TMyFolderNode then
    begin
      SubDir := NodeToStringPath(Child, sPath);
      ForceDirectories(RootDir + SubDir);
    end;

    // node is a type holding data we can save to text file...
    if Obj.Create.ClassType = TMyItemNode then
    begin
      with TMyItemNode(Obj) do
      begin
        // save the file as .txt...
        SubDir := NodeToStringPath(Node, sPath);
        SubDir := RemoveLastFolder(SubDir);
        //...
      end;
    end;

    Child := Node.GetFirstChild;
    while Assigned(Child) do
    begin
      SaveNode(Child);
      Child := Child.GetNextSibling;
    end;
  end;

begin
  RootDir   := OutDirectory + '\';
  SubDir    := '';
  Node      := nil;

  if ForceDirectories(RootDir) then // make sure base folder exists first
  begin
    Node := TreeView.Items[0]; // start from the first tree node (TopItem causes problems)
    while Assigned(Node) do // until node is no longer assigned
    begin
      SaveNode(Node); // call the recursive procedure
      Node := Node.GetNextSibling; // go to the next node
    end;
  end;
end;


Share : facebook icon twitter icon
TTreeView node handles freed after TTreeView's parent changed?

TTreeView node handles freed after TTreeView's parent changed?


By : tordans
Date : March 29 2020, 07:55 AM
Hope that helps i think i've found the answer. use the OnAddition event of the TTreeView to reconnect the node & object as follows:
procedure TForm1.TreeView1Addition(Sender: TObject; Node: TTreeNode); begin TMyObject(Node.Data).TreeNode:=Node; end;
convert a result set with flat column structure into hierarchical data structure

convert a result set with flat column structure into hierarchical data structure


By : Sompri
Date : March 29 2020, 07:55 AM
Hope this helps There are a few ways, and how you do it depends on how robust your solution needs to be.
One would be to just write a couple of objects that had the attributes in the database. Then you could get the result set, and iterate over it, creating a new object each time the key field (for example, "name") changed, and adding it to a list of that object. Then you'd set the attributes appropriately. That is the "quick and dirty" solution.
Building hierarchical order rows from hierarchical table structure

Building hierarchical order rows from hierarchical table structure


By : KYUHO
Date : March 29 2020, 07:55 AM
seems to work fine I am looking for a tricky way to build hierarchical order rows from the following data: , If the order is important then try this:
code :
select [Level],Val from
(
SELECT '0' as [Level], [Col001] as Ord, [Col001] as Val  FROM @DataSource
union 
SELECT '1' as [Level], [Col001]+[Col002] as Ord, [Col002] as Val  FROM @DataSource
union 
SELECT '2' as [Level], [Col001]+[Col002]+[Col003] as Ord, [Col003] as Val  FROM @DataSource
union 
SELECT '3' as [Level], [Col001]+[Col002]+[Col003]+[Col004] as Ord, [Col004] as Val  FROM @DataSource
) as T1
ORDER BY Ord,[Level]
XSLT Create a hierarchical structure from a flat structure by using certain level criteria

XSLT Create a hierarchical structure from a flat structure by using certain level criteria


By : Ch Yang
Date : March 29 2020, 07:55 AM
hop of those help? I want to create a XSD structure from an Excel output using XSLT. But my XSLT does not generate the hierarchical structure, correctly. It has some additional nodes in an element group, if these nodes with same matching parameters are defined in a later group, which has the same level in the hierarchy. , Here is a suggestion using a recursive function:
code :
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:mf="http://example.com/mf"
  exclude-result-prefixes="mf">

  <xsl:output indent="yes"/>

  <xsl:function name="mf:group" as="element()*">
      <xsl:param name="nodes" as="element(node)*"/>
      <xsl:param name="level" as="xs:integer"/>
      <xsl:for-each-group select="$nodes" group-starting-with="node[metaInfo/Level = $level and @groupMaxOccurs != '']">
        <xs:element name="{@nodeTag}" minOccurs="{@minOccurs}" maxOccurs="{@groupMaxOccurs}" id="{metaInfo/ID}">
            <xs:element name="{@nodeTag}" minOccurs="0" maxOccurs="1" id="{metaInfo/ID}"/>
            <xsl:choose>
                <xsl:when test="(current-group() except .)/metaInfo/Level = $level + 1">
                    <xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="current-group() except ."/>
                </xsl:otherwise>
            </xsl:choose>
        </xs:element>
      </xsl:for-each-group>
  </xsl:function>

  <xsl:template match="nodes">
      <xs:schema>
          <xsl:sequence select="mf:group(node, 1)"/>
      </xs:schema>
  </xsl:template>

  <xsl:template match="node">
      <xs:element name="{@nodeTag}" minOccurs="0" maxOccurs="{@segmentMaxOccurs}" id="{metaInfo/ID}"/>
  </xsl:template>

</xsl:transform>
Convert a POJO to Tree structure in Java 8 for representation of data in hierarchical structure

Convert a POJO to Tree structure in Java 8 for representation of data in hierarchical structure


By : user2990861
Date : March 29 2020, 07:55 AM
like below fixes the issue You can use Collectors.mapping() instead of the last Collectors.groupingBy():
code :
public Map<String, Map<String, List<String>>> findCropDetails() {
    List<CropDetailDto> cropdetails = cropRepository.getCropDetails();
    return cropdetails.stream().collect(Collectors.groupingBy(CropDetailDto::getCropName,
            Collectors.groupingBy(v -> v.getVarietyName() == null ? "undefined" : v.getVarietyName(),
                    Collectors.mapping(m -> m.getSubVarietyName() == null ? "undefined" : m.getSubVarietyName(),
                            Collectors.toList()))));
}
{
    "Tomato": {
        "Red Tomato": [
            "Red Tomato 1 quality", 
            "Red Tomato 2 quality"
        ]
    }, 
    "Brinjal": {
        "undefined": [
            "undefined"
        ]
    }
}
public Map<String, Map<String, List<String>>> findCropDetails() {
    List<CropDetailDto> cropdetails = cropRepository.getCropDetails();
    return cropdetails.stream().collect(Collectors.groupingBy(CropDetailDto::getCropName,
            Collectors.filtering(v -> v.getVarietyName() != null, Collectors.groupingBy(CropDetailDto::getVarietyName,
                    Collectors.filtering(m -> m.getSubVarietyName() != null, Collectors.mapping(CropDetailDto::getSubVarietyName,
                            Collectors.toList()))))));
}
{
    "Tomato": {
        "Red Tomato": [
            "Red Tomato 1 quality", 
            "Red Tomato 2 quality"
        ]
    }, 
    "Brinjal": {}
}
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org