0

Anyone know how to drag the report in TppViewer? (Delphi 7) i try to use the dagdrop event and dragover event of ppviewer but failed, anyone can help?

procedure Tfrm1.ppviewer1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  inherited;
  Accept := Source IS TppViewer;
end;

procedure Tfrm1.ppviewer1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  inherited;
  if Source is TppViewer then begin
    TppViewer(Source).Left := X;
    TppViewer(Source).Top := Y;
  end;
end;
user367856
  • 337
  • 1
  • 6
  • 17
  • I'm not sure what `ppviewer` is, but it's not a standard Delphi component, and it's not something popular enough for me to be familiar with... Perhaps it would help if you mentioned what the actual component is, and where it's from? – Ken White Jun 23 '11 at 04:36
  • TppViewer is a component for viewing ReportBuilder reports. Here is a description from the documentation: This component inherits directly from TCustomPanel and provides a surface for displaying a preview of your report. You can use a viewer to create a custom print preview form. To do this, drop a TppViewer component on a form and assign the Report property to a TppReport component. Call the PrintToDevices method at run-time, and the report will be displayed in your viewer. – MGH Jun 23 '11 at 06:23
  • @MGH: Thanks. Not a ReportBuilder user, so I wasn't familiar. :) – Ken White Jun 23 '11 at 14:41

2 Answers2

0

Are you trying to drag a report file into the Viewer? if so biased on the following advice:

You can achieve this by using the following code:

procedure TMainForm.FormCreate(Sender: TObject);
begin
   //Tell Windows that the Report Viewer accepts files
   ShellAPI.DragAcceptFiles(ppViewer1.Handle,True);
   Application.OnMessage   := ApplicationMessage;
end;    

procedure TMainForm.ApplicationMessage(var Msg: TMsg; var Handled: Boolean);
begin    
    if (Msg.hwnd = ppViewer1.Handle) and (Msg.message = WM_DROPFILES) then
    begin
        Handled := ReportFileDrop(Msg);
    end;
end;

function TMainForm.ReportFileDrop(var Msg: TMsg):Boolean ;
 var
    numFiles : longInt;
    buffer : array[0..MAX_PATH] of char;
    l_file:String;
    l_filemsg:TWMDROPFILES;
 begin
    Result := False;

    //Convert the TMsg into a TWMDROPFILES record 
    l_filemsg.Msg    := Msg.message;
    l_filemsg.Drop   := Msg.wParam;
    l_filemsg.Unused := Msg.lParam;
    l_filemsg.Result := 0;

    numFiles := DragQueryFile(l_filemsg.Drop, $FFFFFFFF, nil, 0) ;
    if numFiles > 1 then
    begin
      ShowMessage('You can drop only one file at a time!') ;
    end
    else
    begin
      try
          DragQueryFile(l_filemsg.Drop, 0, @buffer, sizeof(buffer)) ;
          l_file := buffer;

          //Only try and load the report if the file has the correct extension
          if (Length(l_file) > 0) and (ExtractFileExt(LowerCase(l_file)) = '.rtm') then
          begin
             //Load the Report
             Result := True;
          end;
      except
          //Handle errors
      end;
    end;
 end;
Community
  • 1
  • 1
Re0sless
  • 10,678
  • 6
  • 51
  • 66
0

This answer assumes that you are trying to scroll in the report, by dragging.

TReportPreviewer is the Form

ReportViewer is the ppViewer

Dragging is a Boolean

SaveX, SaveY are Integer

procedure TReportPreviewer.ReportViewerMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Dragging := true;
  SaveX := X;
  SaveY := Y;
end;

procedure TReportPreviewer.ReportViewerMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  if Dragging then
  begin
    if ReportViewer.ScrollBox.Visible then
      ReportViewer.ScrollBox.HorzScrollBar.Position := ReportViewer.ScrollBox.HorzScrollBar.Position - (X - SaveX);
    if ReportViewer.ScrollBox.Visible then
      ReportViewer.ScrollBox.VertScrollBar.Position := ReportViewer.ScrollBox.VertScrollBar.Position - (Y - SaveY);
    SaveX := X;
    SaveY := Y;
  end;
end;

procedure TReportPreviewer.ReportViewerMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Dragging := false;
end;

I tried using ScrollBy instead of moving the scrollbar position, but it seemed to reset for some reason.

MGH
  • 1,189
  • 1
  • 10
  • 18