Recent

Author Topic: [CLOSED] ZEOS Change query text at runtime  (Read 2368 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[CLOSED] ZEOS Change query text at runtime
« on: April 19, 2021, 03:20:26 pm »
How can I change query text at run time of design time created objects. With run time created objects I do this

Code: Pascal  [Select][+][-]
  1.   MyQuery := TZQuery.Create(Self);
  2.  
  3.   sSQL := ' SELECT ...';
  4.  
  5.   MyQuery.SQL.Clear;
  6.   MyQuery.SQL.Add(sSQL);
  7.  

but with the design time object it does not work.
« Last Edit: April 22, 2021, 03:36:54 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

zeljko

  • Hero Member
  • *****
  • Posts: 1591
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: ZEOS Change query text at runtime
« Reply #1 on: April 19, 2021, 03:43:44 pm »
sSQL := 'SELECT ....';
MyDesignSQL.Clear;
MyDesignSQL.Add(sSQL);

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: ZEOS Change query text at runtime
« Reply #2 on: April 19, 2021, 03:49:35 pm »
Read the question. It doesn't work.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dseligo

  • Hero Member
  • *****
  • Posts: 1177
Re: ZEOS Change query text at runtime
« Reply #3 on: April 19, 2021, 04:07:25 pm »
What do you mean it doesn't work? Do you have an error?

What does ShowMessage(MyDesignSQL.SQL.Text); show?

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: ZEOS Change query text at runtime
« Reply #4 on: April 19, 2021, 04:13:25 pm »
Nothing, just empty. No errors, just the string is never changed.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: ZEOS Change query text at runtime
« Reply #5 on: April 19, 2021, 04:22:10 pm »
Before you change the SQL, is your Query deaktivated ?

MyQuery.active:= false;

you cannot change the sql on a active query.
regards
Andreas

miab3

  • Full Member
  • ***
  • Posts: 145
Re: ZEOS Change query text at runtime
« Reply #6 on: April 19, 2021, 04:28:42 pm »
Hi,

ZQuery1.Close;
ZQuery1.SQL.Text:='...';

Michał

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: ZEOS Change query text at runtime
« Reply #7 on: April 19, 2021, 04:32:41 pm »
No, it's closed.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: ZEOS Change query text at runtime
« Reply #8 on: April 19, 2021, 04:37:14 pm »
@pcurtis
Do you open the query after you change the sql?  :)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: ZEOS Change query text at runtime
« Reply #9 on: April 19, 2021, 04:42:29 pm »
OK. Just reinstalled  ZEOS and all is OK.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dseligo

  • Hero Member
  • *****
  • Posts: 1177
Re: ZEOS Change query text at runtime
« Reply #10 on: April 19, 2021, 06:13:52 pm »
Before you change the SQL, is your Query deaktivated ?

MyQuery.active:= false;

you cannot change the sql on a active query.

In ZEOS you can. It's automatically closed when you change SQL.Text

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [REOPENED] ZEOS Change query text at runtime
« Reply #11 on: April 20, 2021, 06:21:56 am »
Thats what I thought, but now another problem occurs wiih parameters.

ZQuery complains that it cant find a parameter even if it is in the query. (The same code works fine in runtime  created objects.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: [REOPENED] ZEOS Change query text at runtime
« Reply #12 on: April 20, 2021, 06:36:57 am »
@pcurtis
Quote
Thats what I thought, but now another problem occurs wiih parameters.

ZQuery complains that it cant find a parameter even if it is in the query. (The same code works fine in runtime  created objects.
A small demo please, otherwise we just shot in the dark.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [REOPENED] ZEOS Change query text at runtime
« Reply #13 on: April 20, 2021, 12:43:15 pm »
It's a little more complicated. I'm working on a demo, but first I want to try Laz 2.0.10
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: [REOPENED] ZEOS Change query text at runtime
« Reply #14 on: April 21, 2021, 09:34:08 pm »
It's beginning to look like a 2.0.12 issue or compatibly problem. It works as expected in 2.0.10 and is faster.

Yep Laz 2.0.12 + ZEOS 7.2.8 sucks
« Last Edit: April 22, 2021, 03:41:44 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018