Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

TComboBox clipboard data transformation

Posted on 2012-08-30
7
Medium Priority
?
751 Views
Last Modified: 2012-08-31
Hi,

My question is, how do I intercept text before its pasted into a TComboBox so that I can transform it?

Example of text in clipboard:
"Cow
Dog
Bird
"

Text as it appears in the TComboBox after the paste operation:
"Cow,Dog,Bird"

Regards,

Bill
0
Comment
Question by:wipnav
7 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 2000 total points
ID: 38353033
Hi Bill!

You have to intercept WM_PASTE command for edit of combobox. Something like this:

var
  OldComboEditWndProc: Pointer = nil;

type
  // dummy class to acces protected properties
  TxCombo =  class(TCustomCombo)
  end;

function NewWndProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
  S: String;
begin
  if Msg = WM_PASTE  then
  begin
    // modify clipboard data
    S := ClipBoard.AsText;
    S := StringReplace(S, ^M, '', [rfReplaceAll]);
    S := StringReplace(S, ^J, ',', [rfReplaceAll]);
    ClipBoard.AsText := S;
  end;

  Result := CallWindowProc(OldComboEditWndProc, hWnd, Msg, wParam, lParam);
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  C: TxCombo;
begin
  // setup hook
  if OldComboEditWndProc = nil then
  begin
    C := TxCombo(ComboBox1);
    OldComboEditWndProc := Pointer(SetWindowLong(C.FEditHandle, GWL_WNDPROC, Cardinal(@NewWndProc)));
  end;
end;

Open in new window


Best regards,
Igor
0
 
LVL 19

Expert Comment

by:Thommy
ID: 38353225
This shows you the principle of intercepting clipboard contents before it is pasted into a control...
How to intercept (detect) a Paste command into a TMemo?
How do I intercept the OnPaste event in a TMemo
0
 
LVL 9

Expert Comment

by:ITugay
ID: 38353241
Thommy.
1. That examples demonstraits how to create new control with WM_PASTE intercept. So, it is necessary to create your own control.

2. Memo and combobox has difference in processing WM_PASTE message. When sent to a combo box, the WM_PASTE message is handled by its edit control, instead of combobox itself.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 38353247
Do not use FormPaint event to set new link to WndProc. Best event to do is forms OnCreate. So I modify uppper example ...

var
  CB_OldWindowProc: TWndMethod = nil;
...
procedure CB_NewWindowProc(var Message: TMessage);
var
  S: String;
begin
  if Message.Msg = WM_PASTE  then
  begin
    // modify clipboard data
    S := ClipBoard.AsText;
    S := StringReplace(S, ^M, '', [rfReplaceAll]);
    S := StringReplace(S, ^J, ',', [rfReplaceAll]);
    ClipBoard.AsText := S;
  end;

  CB_OldWindowProc(Message);
end;

procedure TFrom1.FormCreate(Sender: TObject);
begin
  CB_OldWindowProc := Combobox1.WindowProc;
  Combobox1.WindowProc := CB_NewWindowProc;
end;
..

Open in new window

0
 
LVL 9

Expert Comment

by:ITugay
ID: 38353413
sinisav
Did you try to compile and execute your sample?
I suppose no:)

1. procedure CB_NewWindowProc(var Message: TMessage);
Must be "of object".

2. Have you ever catch WM_PASTE in WindowProc of TComboBox?

3. In OnCreate method of form, TComboBox.EditHandle still not initialized (zero value).
0
 
LVL 1

Author Closing Comment

by:wipnav
ID: 38353652
Thank you very much Igor!
0
 
LVL 9

Expert Comment

by:ITugay
ID: 38355164
Always wellcome:)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

581 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