Solved

VirtualDrawTree and Picture loading.

Posted on 2001-07-18
10
796 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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