Solved

Olevariant and Event

Posted on 2003-10-28
7
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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