Recent

Author Topic: One ZConnection component in all application forms  (Read 7199 times)

too

  • Newbie
  • Posts: 1
One ZConnection component in all application forms
« on: September 10, 2007, 11:48:51 am »
I'm trying to place one ZConnection (zeos 6.6.1 beta) component in Lazarus (fpc 2.1.3 win32) on main application form and use it in other forms by setting Connection property of TZQuery components placed on these forms.

  My problem is with Lazarus, because in Delphi (tested on BDS2006) my ZConnection is accessible just by adding main application form (or data module) in uses clasuse of other forms.

  In Lazarus nor I can't type it's name manually ('Invalid property value') or select TZConnection from a data module when it's in uses clause.

  Is it possible to use one connection for all application forms or each form must have it's own connection which is - may I say - sub-optimal ?

tatamata

  • Hero Member
  • *****
  • Posts: 734
    • ZMSQL - SQL enhanced in-memory database
One ZConnection component in all application forms
« Reply #1 on: September 10, 2007, 04:09:15 pm »
Hello.
Yes, it is possible, but only through code (you can't directly set this in design time, but only through code in run-time).
In fact, I'm not quite sure whether you can use it in the way that you put only ZConnection in the main form, but I know for sure that you can put both ZConnection and dataset objects(ZTable, ZQuery) on the main form and then use it on other forms, by providing Dataset property of Datasource object through code.
Let's say you have Unit1 with Form1 and Unit2 with Form2.
You put the ZConnection and all dataset objects (ZTable, ZQuery) on the main form (Form1). You put Datasource components and for example datagrids on the Form2.
You need to have Unit2 in uses clause in interface part of the Unit1. (don't miss it).
You provide Dataset property value while opening the Form2 from Form1, through code:

procedure TForm1.BitBtnOpenForm2Click(Sender: TObject);
begin
  with Form2 do begin  
    //Open required datasets and assign datasets to datasources.
    try
      ZTableTable1.Active:=True;
    except
      ShowMessage('Error while trying to open dataset ZTableTable1.');
    end;
    try
      DatasourceTable1.DataSet:=ZTableTable1;
      DatasourceTable1.Enabled:=True;
    except
      ShowMessage('Error while trying to assign dataset ZTableTable1 to datasource DatasourceTable1.');
    end;
    //Open the form Form2.
    try
      Visible:=True;
    except
      ShowMessage('Error while trying to open form Form2.');
    end;
  end;
end;

You can put all Zeoslib components on the form2 while developing your application. When finished, you copy Zeoslib components to the main form, delete them from the Form2 and provide the beforementioned code.
One more important thing. You need to provide additional uses clause in the IMPLEMENTATION part of the Unit2, in order to be able to programaticaly access Zeoslib components on the Form1 from the Form2. You put "uses Unit2" in interface part of the Unit1 and "uses Unit1" in the implementation part of the Unit2. That's because cross-reference is not allowed in interface part, but is allowed in implementation part.
I hope this will help you.
Have a nice coding day,

Zlatko

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
One ZConnection component in all application forms
« Reply #2 on: September 13, 2007, 11:37:50 am »
Yes currently only in code, but I think a bugreport wishing for this functionality in Lazarus is in order (have same problem, it's bothersome if you need to add fields to queries etc.)

acakadut

  • New Member
  • *
  • Posts: 18
Re: One ZConnection component in all application forms
« Reply #3 on: December 05, 2007, 05:20:42 pm »
Quote from: "too"
I'm trying to place one ZConnection (zeos 6.6.1 beta) component in Lazarus (fpc 2.1.3 win32) on main application form and use it in other forms by setting Connection property of TZQuery components placed on these forms.

  My problem is with Lazarus, because in Delphi (tested on BDS2006) my ZConnection is accessible just by adding main application form (or data module) in uses clasuse of other forms.

  In Lazarus nor I can't type it's name manually ('Invalid property value') or select TZConnection from a data module when it's in uses clause.

  Is it possible to use one connection for all application forms or each form must have it's own connection which is - may I say - sub-optimal ?

hi too,

we had same problem here... but i'm placing zconnection and tzquery in data module, and can't set data source in data controls components on other form, even i had uses data module unit clauses in the form.

i try it on winxp with lazarus 0.9.22 and 0.9.24 and it's not working too...

ewww.....:roll:

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: Re: One ZConnection component in all application forms
« Reply #4 on: December 05, 2007, 07:12:22 pm »
Workaround: I just put a Connection on the form, configure and connect it, get the field names from the query and then just delete the connection again.
The FRED Trainer. (Training FRED with Lazarus/FPC)

acakadut

  • New Member
  • *
  • Posts: 18
Re: RE: Re: One ZConnection component in all application for
« Reply #5 on: December 05, 2007, 10:11:42 pm »
Quote from: "RudieD"
Workaround: I just put a Connection on the form, configure and connect it, get the field names from the query and then just delete the connection again.


hi RudieD,

After delete the connection do u can set datasource on data controls component properties that placed on other form using "uses clauses" ?

would u send the examples source code ?

TIA

acakadut

 

TinyPortal © 2005-2018