Solved

Olevariant and Event

Posted on 2003-10-28
7
484 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

22 Experts available now in Live!

Get 1:1 Help Now