Solved

Olevariant and Event

Posted on 2003-10-28
7
486 Views
Last Modified: 2010-04-05
How to assign an procedure to  an Olevariant?
(Olevariant<--(TNotifyEvent or some thing like it))
0
Comment
Question by:skullvn
  • 3
  • 2
7 Comments
 

Accepted Solution

by:
jgilm earned 50 total points
ID: 9636886
You didn't say what you wanted to do with the OleVariant. I'll give you an example of what you can do, but it is ONLY valid within the context of the currently running instance of the application. You would not be able to use it from another application or from another instance of the same application. With this in mind, here you go (using a TNotifyEvent as the example):

{Global variable}
var
  MyTest: OleVariant;

procedure TForm1.Button1Click(Sender: TObject);
begin
  beep;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ne  : TNotifyEvent;
begin
  ne := self.Button1Click;

  // assign the integer value of the pointer to the method to the OleVariant
  MyTest := Integer(@ne);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  ne2 : TNotifyEvent;
begin
  // convert the OleVariant back to a pointer and have ne2 point to the method.
  @ne2 := ptr(integer(MyTest));

  // call the method
  ne2(self);
end;


Again, this is dependent upon the current execution of the application. You can't store this in a database or a file and expect to be able to use it again during another execution of the application. Because of that, there are a number of better ways to assign methods/procedures/fuctions to variables. However, I believe I answered your question as asked.
0
 

Author Comment

by:skullvn
ID: 9649724
Sorry! But UR code is unusable in my instance!
I try to assign my procedure to DHTMLEdit.DOM.onkeydown (<-- a Olevariant)
and I get a error message: Not implemented!
I don't know why because I can easily assign my procedure DHTMLEdit.Ononkeydown but get very hard in assigning my procedure to DHTMLEdit.DOM.onkeydown. can U help me in solving this problem?
0
 

Expert Comment

by:jgilm
ID: 9651644
Unfortunately I don't know what component you are using nor what you are trying to accomplish. You will have to post a lot more information about your problem.
0
 

Author Comment

by:skullvn
ID: 9656389
OK! I use a TDHTMLEdit. I found TDHTMLEdit contain sub Object DOM, this sub Object contain Onkeydown, a Olevariant. I think I can assign Onkeydown with a TnotifyEvent and try to assign my procedure to it. this is my problem!
0
 

Expert Comment

by:jgilm
ID: 9659207
I found a few links about this control. You might want to do a google search. Because I've never used this component, this is the best I can give you.

My guess is that the event you want to attach a handler to needs an interface. Look at this message in yahoogroups
http://groups.yahoo.com/group/delphi-dhtmledit/message/1495

This group is specifically about the Tdhtmledit control, so you might be able to get more help there.
--jgilm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now