Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87065
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: calling a Event Handler within a class |
| Date | 2022-10-18 14:21 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <tim5oa$3nt3e$1@dont-email.me> (permalink) |
| References | <jr5tj7F6h7bU1@mid.individual.net> |
Am 17.10.2022 um 22:51 schrieb Jens:
> Hello,
> I have a hard coded TSpeedButton on TForm.
> I would like to assign it a OnClick Event Handler in a procedureal
> global function (not a member of a class).
> How can I do this ?
>
> Thanks for ideas.
Have a lambda wich you can cast to a normal function pointer and
access local variables of the function by declaring them as either
static or thread_local depending on if the function needs to be
thread-safe. If you have some captures with that function pointer
this approach doesn't work since you can't cast lambdas with cap-
tures to normal function pointers.
Here's an example how to do this from another context:
a#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <link.h>
#include <dlfcn.h>
using namespace std;
int main()
{
thread_local vector<string> images;
dl_iterate_phdr(
[]( dl_phdr_info* image, size_t size, void* pFn ) -> int
{
try
{
if( *image->dlpi_name )
images.emplace_back( image->dlpi_name );
else
{
Dl_info dlInfo;
if( !dladdr( (void*)image->dlpi_addr, &dlInfo ) )
return 1;
char exePath[PATH_MAX];
if( !realpath( dlInfo.dli_fname, exePath ) )
return 1;
images.emplace_back( exePath );
}
return 0;
}
catch (...)
{
return 1;
}
return 1;
}, nullptr );
for( string const &image : images )
cout << "\"" << image << "\"" << endl;
}
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
calling a Event Handler within a class Jens <paule32.jk@gmail.com> - 2022-10-17 22:51 +0200
Re: calling a Event Handler within a class Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-10-17 14:32 -0700
Re: calling a Event Handler within a class Juha Nieminen <nospam@thanks.invalid> - 2022-10-18 07:06 +0000
Re: calling a Event Handler within a class Jens <paule32.jk@gmail.com> - 2022-10-18 10:06 +0200
Re: calling a Event Handler within a class Juha Nieminen <nospam@thanks.invalid> - 2022-10-18 09:27 +0000
Re: calling a Event Handler within a class JiiPee <kerrttuPoistaTama11@gmail.com> - 2022-10-20 18:36 +0300
Re: calling a Event Handler within a class David Brown <david.brown@hesbynett.no> - 2022-10-18 11:45 +0200
Re: calling a Event Handler within a class Manfred <noname@add.invalid> - 2022-10-19 02:43 +0200
Re: calling a Event Handler within a class Bonita Montero <Bonita.Montero@gmail.com> - 2022-10-18 14:21 +0200
Re: calling a Event Handler within a class Jens <paule32.jk@gmail.com> - 2022-10-19 12:58 +0200
Re: calling a Event Handler within a class Lynn McGuire <lynnmcguire5@gmail.com> - 2022-10-20 00:25 -0500
csiph-web