"프로젝트 관리"에 과제가 있습니다. 하위 모듈이 될 수있는 모듈을 할당해야하므로 재귀 하위 모듈을 모듈에 추가하려고합니다.Delphi TTreeNode는 자식 노드를 부모 노드에 재귀 적으로 추가합니다.
예 :
P (프로젝트) 모듈 (M1, M2, M3, M4). M1 모듈에는 하위 모듈 (M1S1, M1S2, M1S3)이 있으며 하위 모듈 1 (M1S1)에는 여러 하위 모듈 (M1S1S1, M1S1S2, M1S1S3)이있을 수 있습니다.
나는이 코드를 재귀와 TTreeNode를 사용하여 작성했지만 문제는 조건문에 있다고 느낍니다.
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
lGlblProjID := 1;
lGlblProjName := 'Project';
ADOConnectionListner.Connected := true;
try
if ADOConnectionListner.Connected then
begin
RootNode := TreeView2.Items.Add(nil, lGlblProjName);
getSubChild(lGlblProjID, RootNode);
end;
except
on E: Exception do
begin
ShowMessage('Exception Class = ' + E.ClassName);
end;
end;
end;
procedure TForm2.getSubChild(var Pid: Integer; var SubRoot: TTreeNode);
var
lcount, I, lcurrentID: Integer;
lcurrentName: String;
lModuleNode: TTreeNode;
begin
// ShowMessage(IntToStr(Pid)+ ' '+SubRoot.Text);
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('SELECT * FROM treetab Where parent_id =:value1');
ADOQuery1.Parameters.ParamByName('value1').Value := Pid;
ADOQuery1.Active := true;
lcount := ADOQuery1.RecordCount;
for I := 0 to lcount - 1 do
begin
lcurrentID := ADOQuery1.FieldByName('id').AsInteger;
lcurrentName := ADOQuery1.FieldByName('name').AsString;
ShowMessage(' id ' + IntToStr(lcurrentID) + ' dd ' + lcurrentName); // print valu of i
if ((lcurrentID <> 0)and (SubRoot.Text <> '')) then //or
begin
lModuleNode := TreeView1.Items.AddChild(SubRoot, lcurrentName);
getSubChild(lcurrentID, lModuleNode);
end else // if
// lcurrentID = 0
ShowMessage('end reached');
// TreeView1.Items.AddChild(SubRoot, ADOQuery1.FieldByName('name').AsString);
ADOQuery1.Next;
//*********
end;
end;
내가 ID = 1에서만이 경우 프로젝트와 같은 특정 프로젝트에 대한 모든 서브 모듈을 검색 할
.
무엇 "조건문"당신은 문제가있는 말, 그것은 잘못된 것에 대해 우려은 무엇입니까? – MartynA
는 S1 이후 그 다음 마지막 잎 SQL 리턴 전무와 나무가 내장되어 절반 만 P1 -SP -ssp -S1 다음 나무 휴식을 말한다 (1 개) 더 레코드가 SSP에서 고려한다. – user3036212