Board index » delphi » How to select fields at runtime using mouse that I want to select to be copied to clipboard

How to select fields at runtime using mouse that I want to select to be copied to clipboard

I would like to create the functionality within the program for the user to
be able to use the mouse, to
select a rectangle of different fields (TLabels and TEdits) that they can
highlight with the mouse, then
copy to the clipboard.   Anyone have any idea on how to do this?

I've seen some code to select with the mouse, but what I haven't been able
to figure out is how to
identify that in this area are fields to be copied to the clipboard.

TIA

Dale

 

Re:How to select fields at runtime using mouse that I want to select to be copied to clipboard


Quote
In article <86huva$ms...@bornews.borland.com>, Dale Berry wrote:
> I would like to create the functionality within the program for the user to
> be able to use the mouse, to select a rectangle of different fields (TLabels
> and TEdits) that they can highlight with the mouse, then
> copy to the clipboard.   Anyone have any idea on how to do this?
> I've seen some code to select with the mouse, but what I haven't been able
> to figure out is how to identify that in this area are fields to be
> copied to the clipboard.

Dale, are you looking for something like this? You still have to decide
in which format you want to copy the controls data to the clipboard,
of course.

{ aForm: form that contains the controls, must be <> nil
  aRect: rectangle to search, in forms client coordinates
  aList: list to take the references to the found controls, must be
         <> nil. Any previous content is lost!

Quote
}

Procedure GetControlsInRect( aForm: TForm; aRect: TRect; aList: TList );
Var
  temp, result: TRect;
  comp: TComponent;
  i: Integer;
Begin
  Assert( Assigned( aform ));
  Assert( Assigned( aList ));
  aList.Clear;

  // convert aRect to screen coordinates
  MapWindowPoints( aForm.handle, HWND_DESKTOP, aRect, 2 );

  // loop over components on form and look for visible controls
  For i:= 0 To aForm.ComponentCount-1 Do Begin
    comp := aForm.Components[i];
    If comp Is Tcontrol Then
      With TControl( comp ) Do
        If Showing Then Begin
          // get its boundsrect and convert to screen coordinates
          temp:= Boundsrect;
          MapWindowPoints( Parent.Handle, HWND_DESKTOP, temp, 2 );
          // see if rects intersect, and if they do if the result is
          // the same as temp, meaning temp is completely in aRect.
          If IntersectRect( result, aRect, temp ) and
             CompareMem( @result, @temp, sizeof(temp )
          Then
            // add control to list
            aList.Add( comp );
        End;
  End;      
End;

Untested, not even compiled!

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Re:How to select fields at runtime using mouse that I want to select to be copied to clipboard


Thanks, Peter.  That's exactly what I was looking for.  I haven't tried to
compile it yet, so
I'll look over it and see exactly how I need to implement it.  This gives me
some
good direction.

Dale

Peter Below (TeamB) <100113.1...@compuXXserve.com> wrote in message ...

Quote
>In article <86huva$ms...@bornews.borland.com>, Dale Berry wrote:
>> I would like to create the functionality within the program for the user
to
>> be able to use the mouse, to select a rectangle of different fields
(TLabels
>> and TEdits) that they can highlight with the mouse, then
>> copy to the clipboard.   Anyone have any idea on how to do this?
>> I've seen some code to select with the mouse, but what I haven't been
able
>> to figure out is how to identify that in this area are fields to be
>> copied to the clipboard.

>Dale, are you looking for something like this? You still have to decide
>in which format you want to copy the controls data to the clipboard,
>of course.

Re:How to select fields at runtime using mouse that I want to select to be copied to clipboard


Peter, thanks again for the routine.  I have modified the routine to grab
the controls
caption or text property and add it to a StringList, then when I'm finished
I copy that to the clipboard,
and it works great.  For the benefit of anyone that might be reading this
thread I'll post the
revised procedure:

procedure GetControlsInRect( aForm: TForm; aRect: TRect; aList: TList;
aStringList : TStringList );
var
  temp, result: TRect;
  comp: TComponent;
  I: Integer;
begin
  assert( assigned( aform ));
  assert( assigned( aList ));
  aList.Clear;
  // convert aRect to screen coordinates
  MapWindowPoints( aForm.handle, HWND_DESKTOP, aRect, 2 );
  // loop over components on form and look for visible controls
  for I:= 0 To aForm.ComponentCount-1 do
  begin
    comp := aForm.Components[i];
    if comp is Tcontrol then
      with TControl( comp ) do
        //if Showing then
        begin
          // get its boundsrect and convert to screen coordinates
          temp:= Boundsrect;
          MapWindowPoints( Parent.Handle, HWND_DESKTOP, temp, 2 );
          // see if rects intersect, and if they do if the result is
          // the same as temp, meaning temp is completely in aRect.
          if (IntersectRect( result, aRect, temp )) and
             (CompareMem( @result, @temp, sizeof(temp ))) then
             begin
               // add control to list
               aList.Add( comp );
               if comp is TLabel then
                 aStringList.add((Comp as TLabel).caption)
               else
                 aStringList.add((Comp as TCustomEdit).text);
             end;
        end;
  end;
end;

Peter Below (TeamB) <100113.1...@compuXXserve.com> wrote in message ...

Quote
>In article <86huva$ms...@bornews.borland.com>, Dale Berry wrote:
>> I would like to create the functionality within the program for the user
to
>> be able to use the mouse, to select a rectangle of different fields
(TLabels
>> and TEdits) that they can highlight with the mouse, then
>> copy to the clipboard.   Anyone have any idea on how to do this?
>> I've seen some code to select with the mouse, but what I haven't been
able
>> to figure out is how to identify that in this area are fields to be
>> copied to the clipboard.

>Dale, are you looking for something like this? You still have to decide
>in which format you want to copy the controls data to the clipboard,
>of course.

Other Threads