Current archive: 2002.01.08;
Callback Find similar branches← →
Eugene Zelikovsky (2001-12-14 13:58) 
People please explain how to work with CallBack.
Communication Dll with the program.
If you can slice the code.
Eugene Zelikovsky (2001-12-14 14:52) 
Digitman (2001-12-14 14:54) 
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) 
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) 
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) 
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) 
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) 
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) 
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) 
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) 
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) 
If I understand correctly what you need:
procedure MyCallBackregister (proc: pointer); external "mylib.dll";
function cbak (info: pointer)
/ * somewhere on boot * /
TMyCallBackProc = procedure (info: pointer);
procedure MyCallackRegister (addr: TMyCallBackProc); // and don't forget to export it
CbakAddr: = addr;
/ * and this is an event handler * /
procedure Datamodule1PosleAtomnoiVoiny (sender: TTerrorist);
!!! 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) 
Everything is fine ... only the axes woleyshon were sick of ...
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) 
Yes, access voleyshon zadolbali :-)
petr_v_a (2001-12-14 20:35) 
> 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) 
> 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
procedure SomeProc (Reference: pointer; MyCbk: TMyCallback); stdcall;
Call her like this:
SomeProc (Self, @MyCallback);
// 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) 
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) 
In general, I made the method that you suggested work .... but only once ... then he doesn’t care ... does not respond ...
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) 
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) 
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) 
> 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) 
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 ); var MyHandler: TMyProcedure; procedure OtherProcedure (a: Integer; b: Char; c: String ); 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) 
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) 
> TMyProcedure = procedure (a: Integer; b: Char; c: String );
TMyProcedure = procedure (a: Integer; b: Char; c: String );
y-soft (2001-12-15 10:29) 
> 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) 
Thanks to everyone. Earned !!!!!!!
Your approach turned out to be the most working .... with small corrections for my program ...
And thank you for the help ... and an excursion into history !!!!
Pages: 1 whole branch
Current archive: 2002.01.08;
Memory: 0.64 MB
Time: 0.035 c