drama22
asked on
code issue
i have this code to insert some node inside Tvirtuailstringtree it works but some time strange behavior happened
this Tvirtuailstringtree are inside a Tpanel called pnlmc
here is the code
the issue is some times when this code requested its insert the node normal and every thing okay but when its comes to try pnlmc.Visible := True; except end; the pnlmc didn't show and stay invisible and some times it works and shows normal what could be the issue can i write the code better to avoid problems ?
this Tvirtuailstringtree are inside a Tpanel called pnlmc
here is the code
function AddMCVDTMIC(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; AObject: TUMICX): PVirtualNode;
var
Data: PUserONMIC;
begin
Result := AVST.AddChild(ANode);
Data := AVST.GetNodeData(Result);
AVST.ValidateNode(Result, false);
Data^.FObject := AObject;
end;
procedure Tform1.Talkin;
var
Node: PVirtualNode;
Data: PUserData;
UMICX : TUMICX;
begin
Node := lookingTreeView(LineToid);
Data := VDT1.GetNodeData(Node);
if (Node <> nil) then
begin
VDT1.IsVisible[Node] := False;
vstmca.BeginUpdate;
try
vstmca.Clear;
UMICX := TUMICX.Create;
try Data.FObject.istalking := '12'; except end;
umicx.Username := Data.FObject.Username;
umicx.userUid := Data.FObject.userUid;
umicx.istalking := Data.FObject.istalking;
umicx.color := Data.FObject.color;
umicx.image := Data.FObject.image;
try AddMCVDTMIC(vstmca, nil, umicx); except end;
finally
vstmca.EndUpdate;
end;
end;
//
if (recorder.Active = True) and (LineToid = IntToStr(UniqueID)) then
begin
try button1.Visible := false; except end;
try stop1.Visible := True; except end;
end
else if (recorder.Active = false) then // enrecorder check
begin
try button1.Enabled := false; except end;
try button1.Caption := 'streamin'; except end;
end;
try pnlmc.Height := Data.FObject.iHeigh; except end;
try panlmtr.Height := Data.FObject.iHeigh; except end;
try vr.Height := Data.FObject.iHeigh; except end;
try vrl.Height := Data.FObject.iHeigh; except end;
try vrl.Top := 0; except end;
try vr.Top := 0; except end;
try pnlmc.Visible := True; except end;
Try validate.Enabled := True; except end;
end;
the issue is some times when this code requested its insert the node normal and every thing okay but when its comes to try pnlmc.Visible := True; except end; the pnlmc didn't show and stay invisible and some times it works and shows normal what could be the issue can i write the code better to avoid problems ?
ASKER
I would love to see your english suggested in coding manner the code already posted showing how to write it better will help
Am using my phone and definitely it's not suitable to write code, but I will try.
function AddMCVDTMIC(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; AObject: TUMICX): PVirtualNode;
var
Data: PUserONMIC;
begin
Result := AVST.AddChild(ANode);
Data := AVST.GetNodeData(Result);
AVST.ValidateNode(Result, false);
Data^.FObject := AObject;
end;
procedure Tform1.Talkin;
var
Node: PVirtualNode;
Data: PUserData;
UMICX : TUMICX;
begin
Node := lookingTreeView(LineToid);
Data := VDT1.GetNodeData(Node);
//Try
if (Node <> nil) then
begin
VDT1.IsVisible[Node] := False;
vstmca.BeginUpdate;
Try
Try
vstmca.Clear;
UMICX := TUMICX.Create;
Data.FObject.istalking := '12';
umicx.Username := Data.FObject.Username;
umicx.userUid := Data.FObject.userUid;
umicx.istalking := Data.FObject.istalking;
umicx.color := Data.FObject.color;
umicx.image := Data.FObject.image;
AddMCVDTMIC(vstmca, nil, umicx);
except
// what happens in the interface when there is an error (the panel and the buttons)?
end;
finally
vstmca.EndUpdate;
end;
end;
//
if (recorder.Active) and (LineToid = IntToStr(UniqueID)) then
begin
button1.Visible := false;
stop1.Visible := True;
end
else if not(recorder.Active) then // enrecorder check
begin
button1.Enabled := false;
button1.Caption := 'streamin';
end;
// If there should be a situation where the following should not be executed it can be validated here (like when data or node are nil).
pnlmc.Height := Data.FObject.iHeigh;
panlmtr.Height := Data.FObject.iHeigh;
vr.Height := Data.FObject.iHeigh;
vrl.Height := Data.FObject.iHeigh;
//Finally
//activate this try-finally to avoid neglecting the following lines when try-except from above escapes the routine.
vrl.Top := 0;
vr.Top := 0;
pnlmc.Visible := True;
validate.Enabled := True;
//End;
end;
function AddMCVDTMIC(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; AObject: TUMICX): PVirtualNode;
var
Data: PUserONMIC;
begin
Result := AVST.AddChild(ANode);
Data := AVST.GetNodeData(Result);
AVST.ValidateNode(Result, false);
Data^.FObject := AObject;
end;
procedure Tform1.Talkin;
var
Node: PVirtualNode;
Data: PUserData;
UMICX : TUMICX;
begin
Node := lookingTreeView(LineToid);
Data := VDT1.GetNodeData(Node);
//Try
if (Node <> nil) then
begin
VDT1.IsVisible[Node] := False;
vstmca.BeginUpdate;
Try
Try
vstmca.Clear;
UMICX := TUMICX.Create;
Data.FObject.istalking := '12';
umicx.Username := Data.FObject.Username;
umicx.userUid := Data.FObject.userUid;
umicx.istalking := Data.FObject.istalking;
umicx.color := Data.FObject.color;
umicx.image := Data.FObject.image;
AddMCVDTMIC(vstmca, nil, umicx);
except
// what happens in the interface when there is an error (the panel and the buttons)?
end;
finally
vstmca.EndUpdate;
end;
end;
//
if (recorder.Active) and (LineToid = IntToStr(UniqueID)) then
begin
button1.Visible := false;
stop1.Visible := True;
end
else if not(recorder.Active) then // enrecorder check
begin
button1.Enabled := false;
button1.Caption := 'streamin';
end;
// If there should be a situation where the following should not be executed it can be validated here (like when data or node are nil).
pnlmc.Height := Data.FObject.iHeigh;
panlmtr.Height := Data.FObject.iHeigh;
vr.Height := Data.FObject.iHeigh;
vrl.Height := Data.FObject.iHeigh;
//Finally
//activate this try-finally to avoid neglecting the following lines when try-except from above escapes the routine.
vrl.Top := 0;
vr.Top := 0;
pnlmc.Visible := True;
validate.Enabled := True;
//End;
end;
ASKER
i did exactly as what you suggest still issue happend panel did not show some times here is the updated code
i want guarantee that pnlmc panel to be visible
procedure Tform1.Talkin;
var
Node: PVirtualNode;
Data: PUserData;
UMICX : TUMICX;
begin
Node := lookingTreeView(LineToid);
Data := VDT1.GetNodeData(Node);
try
if (Node <> nil) then
begin
VDT1.IsVisible[Node] := False;
vstmca.BeginUpdate;
try
try
vstmca.Clear;
UMICX := TUMICX.Create;
try Data.FObject.istalking := '12'; except end;
umicx.Username := Data.FObject.Username;
umicx.userUid := Data.FObject.userUid;
umicx.istalking := Data.FObject.istalking;
umicx.color := Data.FObject.color;
umicx.image := Data.FObject.image;
AddMCVDTMIC(vstmca, nil, umicx); except end;
finally
vstmca.EndUpdate;
end;
end;
if (recorder.Active = True) and (LineToid = IntToStr(UniqueID)) then
begin
button1.Visible := false;
stop1.Visible := True;
end
else if (recorder.Active = false) then // enrecorder check
begin
button1.Enabled := false;
button1.Caption := 'streamin';
end;
pnlmc.Height := Data.FObject.iHeigh;
panlmtr.Height := Data.FObject.iHeigh;
vr.Height := Data.FObject.iHeigh;
vrl.Height := Data.FObject.iHeigh;
finally
vrl.Top := 0;
vr.Top := 0;
pnlmc.Visible := True;
validate.Enabled := True;
end;
end;
i want guarantee that pnlmc panel to be visible
Alright that will require some more info.
Where in your code you hide that panel?
Make sure you don't have oversight somewhere, for instance when you set pnlmc.Height:= Data.FObject.iHeigh is iheigh having a proper value (i.e > 0)?
Also check, is the procedure talkin gets called atall?
And wherelse do you hide/show the panel?
You need to show more code.
Where in your code you hide that panel?
Make sure you don't have oversight somewhere, for instance when you set pnlmc.Height:= Data.FObject.iHeigh is iheigh having a proper value (i.e > 0)?
Also check, is the procedure talkin gets called atall?
And wherelse do you hide/show the panel?
You need to show more code.
ASKER
I set pnlmc visible to false thats how I hide it and set it to true to show and set it to false again to hide it again I height is not set to zero basically its node that already exist in another list so its guarantee that all data set correctly
ASKER
any idea whats up
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No need to put button.visible in try-except.
My advice would be rearranging your scattered try-except blocks keeping all code under one or multiple try-except for validations enclosed with only one try-finally which contains the visual properties.