farshadmohajeri / extpascal

Automatically exported from code.google.com/p/extpascal
49 stars 28 forks source link

How to populate a combobox? #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi How i can to populate a combobox? i'm traying to populate my ComboBox 
with a SqlServer table, but my combos does not show anithing.

Here is my code:
unit Fmain_ext;

interface

uses
  SysUtils, Classes,
  Ext, ExtPascal, ExtPascalUtils, ExtForm,
  ExtData, ExtGrid, ExtUtil, ExtAir, ExtDd,
  ExtLayout, ExtMenu, ExtDirect, ExtState, ExtTree,
  ExtUxForm,ZStoredProcedure, DB, ZAbstractRODataset, ZAbstractDataset,
  ZAbstractTable, ZDataset, ZConnection;

type
  TFrmMain = class(TExtWindow)
    MyPgControl : TExtTabPanel;
    PgDatos : TExtPanel;
    MyGrd : TExtGridEditorGridPanel;
    PgMensajes : TExtPanel;
    Label1 : TExtFormLabel;
    EdtTexto : TExtFormTextField;
    BtnMensaje : TExtButton;
    ToolBar1 : TExtToolbar;
    BtnBuscar : TExtButton;
    BtnImprimir : TExtButton;
    PnlCboFiltros : TExtPanel;
    LblCargos : TExtFormLabel;
    Label2 : TExtFormLabel;
    CboOficinas : TExtFormComboBox;
    CboCargos : TExtFormComboBox;
    ZTOficinas:TZTable;
    Ds:TDataSource;
    ZSpDBConsulta:TZStoredProc;
    ZDbMain:TZConnection;
    zTCargos:TZTable;
  private
  public
    constructor Create;
    procedure Show;
  end;

implementation

uses
  AppThread;

constructor TFrmMain.Create;
begin
  inherited;
{$I *.inc}
end;  {TFrmMain.Create}

procedure TFrmMain.Show;
begin
  inherited Show;

//Conexion a la BD SQL server
   ZDbMain:=TZConnection.Create(ZDbMain);
   ZDbMain.Catalog:='CreceSucursal';
   ZDbMain.Database:='CreceSucursal';
   ZDbMain.Protocol:='mssql';
   ZDbMain.HostName:='192.168.1.185';
   ZDbMain.Password:='12345';
   ZDbMain.User:='hmoreno';
   ZDbMain.Connect;

//Tabla Oficinas
  ZTOficinas:=TZTable.Create(ZTOficinas);
  ZTOficinas.TableName:='dbo.tClOficinas';
  ZTOficinas.Connection:=ZDbMain;
  ZTOficinas.Open;
  While not zTOficinas.Eof do
     Begin
        CboOficinas.SelectByValue(zTOficinas.FieldByName
('NomOficina').AsString,True);
        zTOficinas.Next;
     end;

//Tabla Cargos
  ZtCargos:=TZTable.Create(ZtCargos);
  ZtCargos.TableName:='dbo.tRhCLCargos';
  ZtCargos.Connection:=ZDbMain;
  ZtCargos.Open;
       While not zTCargos.Eof do
             Begin
                 CboCargos.SelectByValue(zTCargos.FieldByName
('NomCargo').AsString,True);
                 zTCargos.Next;
             end;

end;

end.

Thank You

Database:MSSqlServer
Delphi 7.0
I'm Usin Zeos to stablish a conection with my database:
From Villaflores, Chiapas, Mexico, IcebergDelphi

Original issue reported on code.google.com by delphiic...@gmail.com on 22 Apr 2010 at 1:39

GoogleCodeExporter commented 9 years ago
Use StoreArray. 
Please read Ext JS docs and ExtPascalSamples sources. 

See this example and the source:
http://extpascal.call.inf.br/cgi-bin/ExtPascalSamples.cgi/ShowEditableGrid

Options := '';
while not EOF do begin
  Options := Options + '"' + FielByName('NomCargo').AsString + '"';
  Next;
  if not EOF then Options := Options + ',';
end;
CboCargos.StoreArray := JSArray(Options);

Original comment by wanderla...@gmail.com on 22 Apr 2010 at 2:53

GoogleCodeExporter commented 9 years ago
Ok, Thank you wanderlan, it would be better if you upload more examples with 
conecctions with databases not with XML, if you upload examples with databases, 
Extpascal Would be more understandable.

Thank you. 

Original comment by delphiic...@gmail.com on 23 Apr 2010 at 1:09

GoogleCodeExporter commented 9 years ago
Database examples are in the forum. See ExtendDialer, DemoWeb and d3tkjdt, but 
they
not functional because restrictions or behavior requirements. Use them only as 
guides.

Original comment by wanderla...@gmail.com on 23 Apr 2010 at 1:19