Win x64; laz-main (2.3.0) . Not 2.2.4 due to changes
No, i don't want to open the 'box of Pandora' (a term from a similar topic). But maybe a simple piece of information s missing for to make this happen. If not possible by principle, i'll forget it. - It's Not an issue! Simply an idea.
I post it in General, not LCL, because i'd think it's rather a basic question rather than specific for ShellCtrls stuff.
Imagine for a moment xou have a file change monitor around a shelltreeview who detects that an external usb drive had been attached. I asked my self if it isn't possible to show it up, and indeed that was easily. Because not really an provided "FileInfo" searchrec would be needed. For added folders a correct FileInfo structure would be needed, but here i failed with a SIGSEV.
=== This procedure placed simply for test within ShellCtrls would work:
// Soemhow similar as parts of TCustomShellTreeView.PopulateWithBaseFiles;
procedure TCustomShellTreeView.test_ShAddTreeNode(parNode: TTreeNode; fullpath: String);
var NewNode: TTreeNode; capt: String;
FI: TFileItem; SR: TSearchRec; FindResult: Integer;
begin
if parNode = Nil then
capt := ExcludeTrailingBackslash(fullpath)
else capt := ExcludeTrailingBackslash(ExtractFileName(fullpath));
SR.Name := fullpath; // Really fille SearchRec would be next
FI := TFileItem.Create(SR, '');
// This one here is only for test with add a drive
NewNode := TShellTreeNode(Items.AddChildObject(nil, capt, PChar(capt)));
TShellTreeNode(NewNode).FFileInfo := TFileItem(FI).FileInfo; // Not really needed here, but would work
NewNode.HasChildren:= True;
end;
I'm aware: TCustomShellTreeView.PopulateTreeNodeWithFiles does not really create a SerachRec record. But to apply and assign one as mentioned above is possible. Simply as a pre-exercise for folders, where FileInfo surely is needed-
=== When trying to access the FFileInfo structure within an unit using a helper type, it compiles, but at runtime it throws a SIGSEV.
The debug call stack does show an error at funciton "fpc_ansistr_decr_ref".
Type
TShellTreeNodeEx = class(TShellTreeNode)
private
FFileInfo: TSearchRec;
FBasePath: String;
protected
public
//function ShortFilename: String;
//function FullFilename: String;
property FileInfo: TSearchRec read FFileInfo write FFileInfo; // Make the property public accessible
//function IsDirectory: Boolean;
property BasePath: String read FBasePath;
end;
procedure TExtShellTreeView.yShAddTreeNode(parNode: TTreeNode; fullpath: String);
var NewNode: TShellTreeNode; // or NewNode: TShellTreeNodeEx
capt: String; FI: TFileItem; SR: TSearchRec; FindResult: Integer;
begin
if parNode = Nil then
capt := ExcludeTrailingBackslash(fullpath)
else capt := ExcludeTrailingBackslash(ExtractFileName(fullpath));
SR.Name := fullpath; // Really fille SearchRec would be next
FI := TFileItem.Create(SR, '');
// This one here is only for test via add a drive
//NewNode := TShellTreeNode(Items.AddChildObject(nil, capt, PChar(capt)));
//TShellTreeNode(NewNode).FFileInfo := TFileItem(FI).FileInfo; // Not really needed here, but would work
// This one woould be sufficient to work (the node appear and is expandable):
NewNode := TShellTreeNodeEx(Items.AddChildObject(nil, capt, PChar(capt)));
// THIS COMPILES, BUT SIGSEV'S:
TShellTreeNodeEx(NewNode).FileInfo := TFileItem(FI).FileInfo; /// This line is the problematic one
NewNode.HasChildren:= True;
end;
Is there possibly an easy explanation that this basically wont't work?
If not, i'll forget it...
Attached a simplified test project that triggers the NodeAdd manually (without FileWatcher).