Solved

VirtualDrawTree and Picture loading.

Posted on 2001-07-18
10
802 Views
Last Modified: 2009-12-16
Hi!,

How can i load picture to the Image component at every time when i click Node's image data.

Now i use this code to load images:

procedure TView.VirtualDrawTree1Change(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
var
  Data: PImageData;
  SR: TSearchRec;
  FileName: String;
  Picture: TPicture;
begin
  Data := Sender.GetNodeData(Node);
  ZoomedSizeToOriginal(Sender);
  Picture := TPicture.Create;
  View.Tag:=47;
  if Data <> NIL then
  begin
    FullPathandFileName := Data.FullPath;
    FileName := (Data.FullPath) +  '\' + SR.Name;
    if (SR.Attr and faDirectory <> 0) or CanDisplay(FileName) then
    begin
      Picture.LoadFromFile(Data.FullPath);
      ViewerForm.HorzScrollBar.Range := Picture.Width;
      ViewerForm.VertScrollBar.Range := Picture.Height;
      ViewerForm.ClientWidth := Picture.Width;
      ViewerForm.ClientHeight := Picture.Height;
      ViewerForm.Caption := Data.FullPath + ' - ' +
            Format(' (%d x %d)', [Picture.Width, Picture.Height]);
      ViewerForm.Image1.Picture:=Picture;
      ViewerForm.ClientWidth := Picture.Width;
      ViewerForm.ClientHeight := Picture.Height;
      ViewerForm.HorzScrollBar.Range := Picture.Width;
      ViewerForm.VertScrollBar.Range := Picture.Height;      
      RotatedSizeToOriginal(Sender);
      ViewerForm.Show;
      Picture.Free;
    end;
  end;
end;

But if i change abobe code to OnClick event, OnClick event doesn't include (Sender: TBaseVirtualTree;
  Node: PVirtualNode); those declarations. So if i change original OnClick event to this:

procedure TView.VirtualDrawTree1Click(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
begin

end;

And also required changes to the "type section".
Then compiler complains to me at those changes.
So what can i do?? Because now it loads images every time when clickable content change to another content. And that's not my intention.

Regards Marko
0
Comment
Question by:mhieta
  • 6
  • 4
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6295358
? in a onclick event you could easily use the

ANode := VirtualDrawTree1.GetFirstSelected; like

(from a current project of mine)

  AData := TreeFP.GetNodeData(TreeFP.GetFirstSelected);
  If Assigned(AData) then
  ...

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6295464
just to ask, whats wrong eith the onchange event,
because it is fired also if the keyboard is used
0
 
LVL 2

Author Comment

by:mhieta
ID: 6295588
Yes it's true that the OnChange event fired when keyboard are used. That is good thing. But when i click with mouse then it not load first selected image but it loads next image just fine. And also when i try to load image what is already selected/loaded then it not load again that same image.

Regards Marko
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6297277
? happens not to me

maybe your problem is the SR-Var,
for what is it needed,
because there is no search and no reinit/reset/close
0
 
LVL 2

Author Comment

by:mhieta
ID: 6298552
I have changed above code to the:

procedure TView.VirtualDrawTree1DblClick(Sender: TObject);
var
  Data: PImageData;
  SR: TSearchRec;
  FileName: String;
  Picture: TPicture;
begin
  Data := VirtualDrawTree1.GetNodeData(VirtualDrawTree1.GetFirstSelected);
  ZoomedSizeToOriginal(Sender);
  Picture := TPicture.Create;
  View.Tag:=47;
  if Assigned(Data) then
  begin
    FullPathandFileName := Data.FullPath;
    FileName := (Data.FullPath) +  '\' + SR.Name;
.
.
.
.

I have tried also, OnClick Event at this same code but it not worked at all. OnDblClick works fine. Hmm.. this is strange... but if i want to handle files(ex.delete files) this OnDblClick event suits best for that purpose.

Regards Marko
0
 
LVL 2

Author Comment

by:mhieta
ID: 6298553
I have changed above code to the:

procedure TView.VirtualDrawTree1DblClick(Sender: TObject);
var
  Data: PImageData;
  SR: TSearchRec;
  FileName: String;
  Picture: TPicture;
begin
  Data := VirtualDrawTree1.GetNodeData(VirtualDrawTree1.GetFirstSelected);
  ZoomedSizeToOriginal(Sender);
  Picture := TPicture.Create;
  View.Tag:=47;
  if Assigned(Data) then
  begin
    FullPathandFileName := Data.FullPath;
    FileName := (Data.FullPath) +  '\' + SR.Name;
.
.
.
.

I have tried also, OnClick Event at this same code but it not worked at all. OnDblClick works fine. Hmm.. this is strange... but if i want to handle files(ex.delete files) this OnDblClick event suits best for that purpose.

Regards Marko
0
 
LVL 2

Author Comment

by:mhieta
ID: 6298556
Oops, sorry for sending double...
0
 
LVL 2

Author Comment

by:mhieta
ID: 6299637
One thing is that OnDblClick event works under Win98, but not in the Win2k. What i have to change to get OnDblClick working ok??
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6299744
?? can't reproduce your problem,
all works perfect by me, with onchange, onclick and ondblclick
(but i have not win2k)
0
 
LVL 2

Author Comment

by:mhieta
ID: 6304924
I have now removed these unnecessary lines:
{   FileName := (Data.FullPath) +  '\' + SR.Name;
   if (SR.Attr and faDirectory <> 0) or CanDisplay(FileName) then
   begin }

So now it works ok also under Win2k.

BRgrds Marko
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question