Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #4048 > unrolled thread

Resolving macro

Started byKrystian <softb@softb.pl>
First post2012-09-02 15:30 -0700
Last post2012-09-05 06:28 +0000
Articles 5 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Resolving macro Krystian <softb@softb.pl> - 2012-09-02 15:30 -0700
    Re: Resolving macro dlzc <dlzc1@cox.net> - 2012-09-02 19:28 -0700
    Re: Resolving macro "Wolfgang Riedmann" <wriedmann@gmail.com> - 2012-09-03 06:15 +0000
    Re: Resolving macro Krystian <softb@softb.pl> - 2012-09-04 13:35 -0700
      Re: Resolving macro "Wolfgang Riedmann" <wriedmann@gmail.com> - 2012-09-05 06:28 +0000

#4048 — Resolving macro

FromKrystian <softb@softb.pl>
Date2012-09-02 15:30 -0700
SubjectResolving macro
Message-ID<e7c3ec46-c217-496a-999a-7d7bf5182cf0@googlegroups.com>
Hi,

1.
How to evaluate such condition :
local cCondition1, cValue as String
local nValue as Real4

 cCondition1 := "srv1:field1 $ cValue .and. str(srv1:field2) = str(nValue)"

I would like to create one string operating on different servers and fields and then use it in such way : if ?Eval?(cCondition) ... else .... endif

2.
Why it does not work - a runtime error occurs : variable not initialized
local cKody as string
local srv as object

	srv := DbServer{'dbase_file'}
	srv:Eval({|x| cKody += x:AnyField}, {|x| x:AnotherField < 'K'})

Thanks in advance
Krystian

[toc] | [next] | [standalone]


#4049

Fromdlzc <dlzc1@cox.net>
Date2012-09-02 19:28 -0700
Message-ID<e7821f0c-d633-4ab7-8fe3-c967a7ffcb38@googlegroups.com>
In reply to#4048
Dear Krystian:

On Sunday, September 2, 2012 3:30:50 PM UTC-7, Krystian wrote:
...
> local cCondition1, cValue as String
...
>  cCondition1 := "srv1:field1 $ cValue .and. str(srv1:field2) = str(nValue)"

You cannot use local-scoped variables in macros.  The name is lost at compile time.  cValue and nValue are gone... reduced to memory pointers.

David A. Smith

[toc] | [prev] | [next] | [standalone]


#4051

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2012-09-03 06:15 +0000
Message-ID<aaj08bF36oU1@mid.individual.net>
In reply to#4048
Hi Krystian,

as David wrote: local variables are not maintained.

Unfortunately, DBServer:Eval does not let you pass parameters to the
codeblock, so this cannot work, and DBServer:Eval cannot be used - you
need to loop the DBServer yourself.

You could use an object and it's Eval method

class MyCB
	export cKody as string

method Eval( oSrv ) class MyCB

	cKody += oSrv:Anyfield

	return self

function ServerEval( oSrv )
	local oCB as MyCB

	oCB		:= MyCB{}
	oSrv:GoTop()
	while ! oServer:EOF
		Eval( oCB, oSrv )
		oServer:Skip()
	end

	return oCB:cKody


HTH

Wolfgang

[toc] | [prev] | [next] | [standalone]


#4061

FromKrystian <softb@softb.pl>
Date2012-09-04 13:35 -0700
Message-ID<92d66259-b70b-4dda-8fcd-df94472fea23@googlegroups.com>
In reply to#4048
W dniu poniedziałek, 3 września 2012 00:30:50 UTC+2 użytkownik Krystian napisał:
> Hi,
> 
> 
> 
> 1.
> 
> How to evaluate such condition :
> 
> local cCondition1, cValue as String
> 
> local nValue as Real4
> 
> 
> 
>  cCondition1 := "srv1:field1 $ cValue .and. str(srv1:field2) = str(nValue)"
> 
> 
> 
> I would like to create one string operating on different servers and fields and then use it in such way : if ?Eval?(cCondition) ... else .... endif
> 
> 
> 
> 2.
> 
> Why it does not work - a runtime error occurs : variable not initialized
> 
> local cKody as string
> 
> local srv as object
> 
> 
> 
> 	srv := DbServer{'dbase_file'}
> 
> 	srv:Eval({|x| cKody += x:AnyField}, {|x| x:AnotherField < 'K'})
> 
> 
> 
> Thanks in advance
> 
> Krystian

Hi to All

Thank you for answers; I understand the idea proposed by Wolfgang but i do not understand why it must be achieved in so indirect way. What do i gain using objects instead of simply & operator ? I found, that if i declare variables as private and check in the "undeclared variables" check box in the "entity compiler options" everything is OK (like in old good clipper), but still i do not realize the advantage of Wolfgang's method - as a self-taught programmer on the beginning of adventure with CA.

Thank you
Krystian

[toc] | [prev] | [next] | [standalone]


#4062

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2012-09-05 06:28 +0000
Message-ID<aao9oaF2mmU1@mid.individual.net>
In reply to#4061
Hi Krystian,

it is a little bit hard to explain: variables, that are existent at the
time of the codeblock creation are not more reachable when the
codeblock is executed.
Therefore you need a possibility to store variables in the codeblock,
and with a normal codeblock this is not possible.

But instead of a codeblock you can pass also an object with an Eval
method to any function that requires a codeblock. This gives you the
possibility to store any variables you need in the object and retrieve
them at codeblock execution.

So this will work:

class MyDbCounter
	export nCount as dword

method Eval() class MyDBCounter

	++nCount

	return true

function Start()
	local oServer as DBServer
	local oC as MyDbCounter

	oServer := DBServer{ "any valid.dbf" }
	oServer:GoTop()
	oC := MyDBCounter{}
	DebOut( "Count:" + NTrim( oC:nCount ) )
	oServer:Eval( oC )
	DebOut( "Count:" + NTrim( oC:nCount ) )
	oServer:Close()

	return

HTH

Wolfgang

	

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web