Host Structure in a component

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Host Structure in a component

4D Tech mailing list
I know this topic has been covered in General before but there are some things I am not sure about and i seem to be having a problem.

I want to get the details of a host structure in a COMPILED component.


ARRAY LONGINT($tableNums;0)
ARRAY TEXT($tableNames;0)
Begin SQL
 SELECT TABLE_ID
 FROM _USER_TABLES
 INTO :$tableNums;

 SELECT TABLE_NAME
 FROM _USER_TABLES
 INTO :$tableNames;
End SQL

I know that code works inside the host database uncompiled and my reading suggested this is how i should be getting the structure in the component. However i am getting an error(just after this SQL. (error 1430) the variable does not exist.

I was wondering if anyone could enlighten me where I am going wrong here.


Thanks.

Nigel Greenlee


 


**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Host Structure in a component

Patrick Emanuel
I had no issue with this kind of code from a compiled component.
However, you can write:

ARRAY LONGINT($tableNums;0)
ARRAY TEXT($tableNames;0)
Begin SQL
 SELECT TABLE_ID , TABLE_NAME
 FROM _USER_TABLES
 INTO :$tableNums, :$tableNames;
End SQL
Patrick EMANUEL
------------------------------------------------------------
Administrator
www.association-qualisoft.eu
(Soft1002, Simply Asso & QS_Toolbox)
Reply | Threaded
Open this post in threaded view
|

RE: Host Structure in a component

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Getting an error that the variable does not exist only while in compiled mode?

Maybe the issue is the local variable (variable starting with $)?
http://doc.4d.com/4Dv15/4D/15.3/Import-and-Export.201-3151369.en.html#1040799

-Tim



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Host Structure in a component

4D Tech mailing list
the code "seems OK..."

doesn't it work inside a different host?
what if you rename the arrays to something different?

local variables are permitted in that context,
but sometimes strange things occur.



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Host Structure in a component-Enhancing 4D Code-you really want to see this

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Hi

Thanks(scroll down for link to a nice video)

Dont really know what was going on. Think i was being blind to an accidental reference to $tableNums. All working now.-replaced the locals with process vars and tidied it up and its all good.

Incidentally i had lots of fun with updating records using an execute immediate statement with a built line of the update where part of the update was a long bit of text that contained sections lifted from my code-all kinds of characters i there, even wrapped in [ ] i was getting errors-changed to not using 'execute immediate’ and my errors went away.

Does anyone know a better way of to check if the table/structure exists.? i currently call this..and other than a Session Variable(<>DIff_bo_TablesChecked) don’t know of a way to avoid it

Begin SQL
CREATE DATABASE IF NOT EXISTS DATAFILE  <<DataPath>>;
 Use LOCAL DATABASE DATAFILE  <<DataPath>> AUTO_CLOSE;  
EXECUTE IMMEDIATE :SQLTEXT;
Use database SQL_Internal;
End SQL


This code is for my own Code Manager. I have existing and long standing code that runs on my system setting method headers and saving out copies of the code and writing to a changes document a summary of the changes to a method. This code has always been a bit slow(there is a detectable delay as you close methods)

 I have always been guilty of forgetting to type my variables  and inspired by a comment on here about extracting variables from a method returned to a half baked piece of code I had that did the same..the difference was I want to extract not just locals i want to extract all the variables and make sure declarations are made at the top of methods.

Being a bit obsessive I have been beating through this in my spare time over the past couple of weeks. Extracting Locals and interprocess variables was pretty easy the challenge was how to successfully extract variables. I was EVENTUALLY happy with the result of this(plenty of gotchas along the way)-having a method that ran over all my code and build the declarations.

The problem then was that it too was a bit slow-parsing a long method line by line uncompiled is just never going to be rocket fast so I wanted to move it to a component. I already had a component as part of my code manager because DIFFING two methods(based on 4D code published by David Dancy) was REALLY slow uncompiled and I had put that in a component.

I slowly moved parts of my 'variables extractor’ to the component till i had something that could be included in my code manager to build the variables on method save-now i can extract the variables from even in a large method in just about no time.

The SQL code I was working on was to  to store the history of changes in an external structure(I had already started on that-previously this was written out to a document and of limited use). Moving them to an external database means I can now easily create a view of method changes to show all the history of a piece of code, and do some things around that(fix/revert/report etc) ...thats my next little side project.

 The compiled component code manager is now working the way I want and this nicely enhances my code

I thought i would share a little video of what happens in my code…

https://www.dropbox.com/s/j5x0vy45j1ikocg/Automatical%20Typing%20of%20variables.mp4?dl=0 <https://www.dropbox.com/s/j5x0vy45j1ikocg/Automatical%20Typing%20of%20variables.mp4?dl=0>

Answers to inevitable questions:-

Did i have to change my structure to do this? Not at all. The are a couple methods in my host code-less now than before the component and I hoping to reduce them down further as well.

How does it know the type of the variables? I use a naming convention so it recognises by the variable type..if you have no naming convention it would be hard to do. I read the compiler directives as well

What about $1 etc? it recognises them by assignment(or from the compiler directives).  Almost always my code has $_l_MyVariable:=$1(In the top of the code) so we can deduce that $1 is a longint(and $_l_MyVariable:=$1-> means $1 is a pointer!). I have considered using assignments to work out the type of all variables-but as I use a naming convention It was work I did not need to do.

What about ‘badly’ named variables. If i lazily type For($i;1;…)..old habits die hard! then the code wont know what the variable is so will declare //C_UNKNOWN..so i can just find them and fix ‘em..-

Could a different naming convention be used? Yes. -i have currently hard coded my naming convention but i plan to change that to pick up a document in which any naming convention can be defined

Could a different header model by used Yes-again i currently have my headers(different rules for project methods, form methods, triggers, object methods) hard coded  i also plan to change this to pick up the header definitions from documents.

What about if there are methods you don’t want this to happen in. I have a few method like that-as this code was in my main database I certainly did not want it editing itself! and you never want it doing this in the error handling methods) at the moment the ‘ingore’ methods are hard coded but i could move that to pick up a list of methods and method groups(all methods starting xxx) from a document.

Does this run on the server? Currently my development is single user so my repository is on single user, I will be updating this to run client server in a challenging environment soon.

Could the Code manager run without the variables declaration? Yes as I have just added the variables declaration on it was running fine without it before(its just component-ized now).

What about forms? Disctint from Form Objects and Form Methods.. I also parse forms-as there is no macro triggered when you close a form in the design environment this is handled slightly differently and currently i have not moved that code to the component. When I parse a form I get a complete(almost) descriptor of the form-all the objects-positions-styles-activated events etc. I will be moving that to the component shortly.

If anyone wants to implement a version of this themselves please contact me-i would be happy to adjust it to suit other requirements. I don’t advise trying to replicate extracting the variables-only because there was a lot of trial and error to get it right-and i cant even now be certain something wont trip it up-but then if i get some weird declaration in my code it wont take long to find it!











> On 13 Mar 2017, at 19:16, Timothy Penner via 4D_Tech <[hidden email]> wrote:
>
> Getting an error that the variable does not exist only while in compiled mode?
>
> Maybe the issue is the local variable (variable starting with $)?
> http://doc.4d.com/4Dv15/4D/15.3/Import-and-Export.201-3151369.en.html#1040799
>
> -Tim
>
>
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Host Structure in a component-Enhancing 4D Code-you really want to see this

4D Tech mailing list
Hi Nigel,

One word:  Niiiiiice!

How did you insert an event 'on object method close', when you added code
to the button?


Bob Miller
Chomerics, a division of Parker Hannifin Corporation




**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************