Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];


Callback Find similar branches

Eugene Zelikovsky   (2001-12-14 13:58) [0]

People please explain how to work with CallBack.
Communication Dll with the program.
If you can slice the code.
Thank you!

Eugene Zelikovsky   (2001-12-14 14:52) [1]

HELP !!!!!

Digitman   (2001-12-14 14:54) [2]

Well, I already gave you a fragment illustrating how to connect your event handler to a component created in a DLL! How do you like the event handler not Callback?

Eugene Zelikovsky   (2001-12-14 16:09) [3]

No, your advice didn’t work: (... EventHendlr will not work .... maybe all the same about CallBack and tell me ....

Digitman   (2001-12-14 16:14) [4]

and this is CallBack !!!!!!!!!!!!!!!!!!!!!!
the fact that you have something “not being transmitted” somewhere is your misunderstanding of the mechanism for assigning event handlers. and just that. and you immediately - "not transmitted"))))))))))) Yes, everything is wonderful transmitted!)) Look for a mistake at home.

Eugene Zelikovsky   (2001-12-14 16:22) [5]

Upss ....
Okay, I got it ... :) callback ... okay ... then the question!
What did you write then .... about the dll part I understood .. yes it works correctly .... it sends an address to EventHendler .... OK
But here's a hitch with the program ... for more details? What you have written ... does not perceive EventHendler .... I confess I did not even understand what we are doing in the program .....

Digitman   (2001-12-14 16:27) [6]

IN WHICH PROGRAM? Both DLL and EXE are programs. Use, for example, terms such as "calling code" and "called code." Otherwise - not a damn thing is clear what you're talking about ....

Eugene Zelikovsky   (2001-12-14 16:35) [7]

OK :)
But with the Calling Code, a hitch ... can I give you more details? What you have written ... does not perceive EventHendler .... I confess I did not even understand what we are doing in it. .....
And is it also mandatory to pull Socket ... in the calling code?

Digitman   (2001-12-14 16:54) [8]

What does it mean to "pull"? How long are we going to talk stupidly in jargon ????

The TSocketServer that you created in the DLL informs you in the Socket parameter of the OnClientRead event about which particular client has sent you the data packet.

Digitman   (2001-12-14 16:56) [9]

Bring YOUR allegedly broken code fragment - I’ll comment on where you are doing what specifically. Well, how do you explain on the fingers?

Eugene Zelikovsky   (2001-12-14 17:35) [10]

Here is what I wrote in the DLL:
procedure ClientRead (servers: TServerSocket; EventHandler: TSocketNotifyEvent); export; begin ServerS.OnClientRead: = EventHandler; end;
In Challenge code:
Type TForm1 = class (TForm) Memo1: TMemo; procedure OnClientRead (Sender: TObject; Socket: TCustomWinSocket); procedure TForm1.OnClientRead (Sender: TObject; Socket: TCustomWinSocket); begin memo1.lines.Insert (0, Socket.ReceiveText); end;

And what else was meant:

SetOnClientRead (ServerSocketInstanceCreatedInDll, MyObjectInstance.OnClientRead);

petr_v_a   (2001-12-14 18:32) [11]

If I understand correctly what you need:

in exe

procedure MyCallBackregister (proc: pointer); external "mylib.dll";

function cbak (info: pointer)
showmessage ("oops!");

/ * somewhere on boot * /
MyCallackRegister (@cbak);

in dll

TMyCallBackProc = procedure (info: pointer);
CbakAddr: TMyCallBackProc;

procedure MyCallackRegister (addr: TMyCallBackProc); // and don't forget to export it
CbakAddr: = addr;

/ * and this is an event handler * /
procedure Datamodule1PosleAtomnoiVoiny (sender: TTerrorist);
CbackAddr (sender);

!!! I wrote right here, maybe where the thread, the che-thread does not grow together, but the idea does not suffer from this

Eugene Zelikovsky   (2001-12-14 20:01) [12]

> petr_v_a
Everything is fine ... only the axes woleyshon were sick of ...

Bad question
what did you mean

function cbak (info: pointer) begin showmessage ("oops!"); end;

where it is not finished ... what function .... but it is so a glitch ..
and how to frighten off these very accesses?
I don’t know what to think ...
The program bends at a moment similar to this in your code ... CbakAddr: = addr;

Anatoly Podgoretsky   (2001-12-14 20:19) [13]

Yes, access voleyshon zadolbali :-)

petr_v_a   (2001-12-14 20:35) [14]

> Eugene Zelikovsky
and I warned :) I idea planted that everything is in code correctly, I do not answer.

y-soft   (2001-12-14 21:34) [15]

> Eugene Zelikovsky ©
You can not use the method as callback functions, but pass as a parameter a separate link to the calling object and the address of the linear adapter function. It is even better to use the stdcall convention for working with Dll (we will achieve better compatibility with other development tools). For example, like this (only a general approach):

TMyCallback = procedure (Reference: pointer); stdcall; // Callback adapter procedure

Exported procedure:

procedure SomeProc (Reference: pointer; MyCbk: TMyCallback); stdcall;

Call her like this:

procedure TMyObject.CallSomeProc;
SomeProc (Self, @MyCallback);

procedure TMyObject.SomeMethod;
// some action

Callback procedure handler:

procedure MyCallback (Reference: pointer); stdcall;
TMyObject (Reference) .SomeMethod;

Maybe you will like this option more :)

petr_v_a   (2001-12-14 21:49) [16]

> y-soft
But “the method’s callback functions aren’t just“ Can’t and don’t be used, "and if you use it, then the accessory is guaranteed

Eugene Zelikovsky   (2001-12-14 23:14) [17]

> petr_v_a
In general, I made the method that you suggested work .... but only once ... then he doesn’t care ... does not respond ...
> y-soft
I did not understand your method
what did you mean:
procedure MyCallback (Reference: pointer); stdcall; begin --- TMyObject (Reference) .SomeMethod; ---//here end;

iZEN   (2001-12-14 23:36) [18]

Work with DLL in any more or less decent book on Delphi is described.
I bought a book, read it, understood (it is necessary!).

And why are we talking and planting gardens here?

PS A person does not know how to work with a DLL - let him study, and then he already thinks whether it is worth stuffing sockets there.

Eugene Zelikovsky   (2001-12-14 23:52) [19]

in a no less decent book, work with a DLL is described like:
you can put that yes function that will count you 2 + 2 ...
And the work with callback is mainly written in the COM / DCOM section and that’s the whole thing .... with which I am just starting to learn ...
Well, not when I didn’t use CALLBACK and .... now I want to learn ....
and there is nothing to be indignant ... If smart tell me ... if there is no silence ...

petr_v_a   (2001-12-15 00:39) [20]

> Eugene Zelikovsky Why once, it’s in the logic of the program, look, besides you they’re lying who will figure it out, at least that's another question. Work hard, debug further himself, and do not pay attention to anyone :)

iZEN   (2001-12-15 01:30) [21]

callback - the so-called "callback". It was invented so that any program could “palm off” its function (its address) to another program, so that the latter (another program) could call it in the first without recompiling and / or analyzing the code of the first program - this is rude.

Callbacks are used in any windowed program with event handling: for example, event handlers written by a programmer are direct participants in callback calls from the main function of the Windows window event handler. That's all.

Yes, even when writing a button event handler in Delphi, you write a CallBack procedure, which the compiler will then assign to the button window functions.

Even in early Pascal, the procedural type is used to provide the callback mechanism (callback, or late call):
type TMyProcedure = procedure (a: Integer; b: Char; c: String [23]); var MyHandler: TMyProcedure; procedure OtherProcedure (a: Integer; b: Char; c: String [83]); begin WriteLn (a); WriteLn (b); WriteLn (c); end; BEGIN ... MyHandler: = OtherProcedure; ... MyHandler (10, "f", "Greetings from the bottom of my heart!"); END.

So, it is better to first study the work with the DLL, it will be more logical.

iZEN   (2001-12-15 01:34) [22]

I advise you not to connect the concepts of callback and COM / DCOM, this does not help much in studying the problem.

iZEN   (2001-12-15 01:37) [23]

> TMyProcedure = procedure (a: Integer; b: Char; c: String [23]);
TMyProcedure = procedure (a: Integer; b: Char; c: String [83]);

y-soft   (2001-12-15 10:29) [24]

> Eugene Zelikovsky ©


The library does not have to know the type of our object at all, therefore, we simply pass an untyped pointer when the procedure is called from the library. There are languages ​​in which reference types are completely absent - in this case it is worth casting a pointer to our object to Integer.

procedure TMyObject.CallSomeProc; begin SomeProc (Self, @MyCallback); end;

In the Dll code:

procedure SomeProc (Reference: pointer; MyCbk: TMyCallback); stdcall; begin //... Some actions MyCbk (Reference); // Call Callback end;

Accordingly, in the callback procedure handler, we explicitly perform the type conversion

procedure MyCallback (Reference: pointer); stdcall; begin TMyObject (Reference) .SomeMethod; //here!!! end;

In COM / DCOM, by the way, completely different mechanisms are used for similar purposes.

Eugene Zelikovsky   (2001-12-15 13:00) [25]

Thanks to everyone. Earned !!!!!!!
> petr_v_a
Your approach turned out to be the most working .... with small corrections for my program ...
> iZEN
And thank you for the help ... and an excursion into history !!!!

Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];


Memory: 0.65 MB
Time: 0.031 c
2001-12-19 19:38
Hide shape

2001-12-04 09:47
DTS + Delphi

2001-11-02 10:44
how to determine the window handle over which the mouse is located

2001-12-19 17:15
Event form

Dmitry D.
2001-12-07 08:00
Error BDE got out ... I do not understand what could be the problem

afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic Indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish Thai turkish Ukrainian urdu Vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
English French German Italian Portuguese Russian Spanish