Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-05

CodeTools On Event insert? detect

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

I am looking for a way to detect when someone has added an event in the ide, for example button1click..

When someone double clicks a button in lazarus it generates code in the IDE for the event handler procedure..

I want to intercept/detect this, and add

   SomeCode();

between the begin/end of the event, i.e. on button 1 click.

Does codetools provide some way to do it?

It has a way to search the source code for a procedure and enter code, but how do you detect when an event is added to the source code?

Reply by email

Mattias Gaertner
to Unknown author
Show quoted text 8 lines
[...] I want to intercept/detect this, and add SomeCode(); between the begin/end of the event, i.e. on button 1 click. Does codetools provide some way to do it?

Donald Ziesig added templates to alter the inserted code snippets. Please update svn, compile the IDE with
-dEnableCodeCompleteTemplates and restart it.

Read the header notes in
lazarus/components/codetools/codecompletiontemplater.pas

Default templates are defined in
components/codetools/codecompletiontemplates.xml

You can choose your own template file in Tools / Options / Codetools / Code creation / Template file.

Mattias

Reply by email

Unknown author
to Mattias Gaertner
Mattias Gaertner wrote 25 lines
On Wed, 24 May 2017 13:43:10 -0500 Lars via Lazarus wrote: > [...] > I want to intercept/detect this, and add > > SomeCode(); > > between the begin/end of the event, i.e. on button 1 click. > > Does codetools provide some way to do it? Donald Ziesig added templates to alter the inserted code snippets. Please update svn, compile the IDE with -dEnableCodeCompleteTemplates and restart it. Read the header notes in lazarus/components/codetools/codecompletiontemplater.pas Default templates are defined in components/codetools/codecompletiontemplates.xml You can choose your own template file in Tools / Options / Codetools / Code creation / Template file.

Thanks, I will try. Is it a special Define because it is a new untested feature waiting for approval?
If so I could be a tester

Reply by email

Unknown author
to Mattias Gaertner: On Wed, 24 May 2017 13:43:10 -0500 Donald Ziesig added templates to alter the inserted…
Show quoted text 8 lines
> [...] > I want to intercept [...] and add > > SomeCode(); > > between the begin/end of the event, i.e. on button 1 click. > > Does codetools provide some way to do it?

Found this discussions about it too:

http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-March/086457.html

http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-RFC-Code-tools-Feature-td4036425.html

That's interesting that Michael V. C. wanted logging at begin/end of code snippets in procedures, because that's exactly what powtils had to do but it looks kind of ugly at the source level to have IFDEF DEBUG at the end and begin of each procedure, but that's how I did it..

But, this requirement that I need has nothing to do with that, it's for something else.. but still interesting!

Reply by email

Mattias Gaertner
to Unknown author: Thanks, I will try. Is it a special Define because it is a new untested feature waiting…
Show quoted text 6 lines
[...] > Please update svn, compile the IDE with > -dEnableCodeCompleteTemplates and restart it. [...] Thanks, I will try. Is it a special Define because it is a new untested feature waiting for approval?

Yes, and it is waiting for a discussion about the template file. Attributes, format, flexibility.

If so I could be a tester

Yes, please.

Mattias

Reply by email

Unknown author
to Mattias Gaertner

Mattias, I'm still having issues figuring out exactly what Donald Z.'s code does and how to use it, but is there even a way to "hook" the ide event insertion currently? i.e. if you throw a Button on a form and double click it, I want to hook into that, and insert code immediately after the event has been inserted into the ide text edit window..

If this feature is currently not implemented I can work on a patch today that does it, however I don't want to work on a patch if this feature already exists and I just can't find it.

Something like: OnAfterEventInsert codetools/lazintf trigger

- User adds button 1 to form
- user double clicks button 1
- code is inserted inbetween begin/end automatically

I think the templates may help this but is there really a hook like this in code tools where you can hook into the events inserted into the IDE when a user double clicks a button/widget or double clicks the event in the object inspector?

Reply by email