Italian community of Lazarus and Free Pascal

Programmazione => Componenti Aggiuntivi => Topic aperto da: tiberi72 - Febbraio 14, 2012, 04:01:22 pm

Titolo: problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:01:22 pm
Ciao,
ho creato un programma con abbinato un report di lazreport.
Il programma esegue  per 2 volte la visualizzazione dei record di una tabella abbinata ad un dataset di lazreport
La prima volta non ci sono problemi: riesco a visualizzare il report con .loadfromfile e .showreport
Al secondo giro' ,pero', quando eseguo nuovamente .loadfromfile e .showreport, il programma mi visualizza il report precedente, senza tener conto che i record dentro la query associata al dataset di lazreport sono cambiati
Come posso fare per fare il refresh del report?
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 04:06:33 pm
Domanda stupida, ma tu il report lo chiudi prima di ricaricarlo con i dati nuovi oppure no?! La query la chiudi e la riapri oppure esegui un refresh?!
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:11:10 pm
in pratica eredito la query, il dataset e il tfrreport da una form, quindi non lo chiudo e non lo apro, se non per quello che gestisce gia' in automatico lazarus.
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 04:14:55 pm
Da quello che so io il report lo aggiorni chiudendolo e riaprendolo. Se qualcuno conosce qualche altro metodo allora lo segnali!
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:19:54 pm
con quali comandi lo chiudi e lo riapri?
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 04:21:17 pm
bhe ma scusa il report si chiude a mano! Mi sa che stai usando uno strumento errato per far vedere dei risultati, da come dici sembra quasi che usi il report come se fosse un interfaccia con qui leggere i dati!
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:25:26 pm
questo e' il codice che uso per aprire il report:
Codice: [Seleziona]
  frreport1.FileName:=IncludeTrailingPathDelimiter(GetCurrentDir) + 'gls.lrf';
  frReport1.LoadFromFile(IncludeTrailingPathDelimiter(GetCurrentDir) + 'gls.lrf');
  frReport1.ShowReport;
il codice e' inserito nell'evento onclick di un button
Al primo click il report si apre e visualizza i record corretti
Cambio i dati della tabella associata e proseguo.
Al secondo click il report si apre ma ci sono ancora i record di prima, come se la videata non si fosse aggiornata.
Devo fare per caso un frreport1.free dopo averlo visualizzato?
Pero' poi in questo caso al secondo giro non visualizzerei nulla a meno che non ricreo l'oggetto, giusto?
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:31:20 pm
A scanzo di equivoci ti mando anche il codice della form:
Codice: [Seleziona]
object Form1: TForm1
  Left = 492
  Height = 216
  Top = 324
  Width = 583
  Caption = 'Form1'
  ClientHeight = 216
  ClientWidth = 583
  Icon.Data = { ......

  }
  OnCreate = FormCreate
  LCLVersion = '0.9.31'
  object CmdEsegui: TButton
    Left = 453
    Height = 47
    Top = 96
    Width = 107
    Caption = '&Esegui'
    OnClick = CmdEseguiClick
    TabOrder = 0
  end
  object Label1: TLabel
    Left = 32
    Height = 14
    Top = 23
    Width = 21
    Caption = 'File:'
    ParentColor = False
    OnClick = Label1Click
  end
  object Label2: TLabel
    Left = 32
    Height = 14
    Top = 51
    Width = 29
    Caption = 'Maut:'
    ParentColor = False
    OnClick = Label1Click
  end
  object Label3: TLabel
    Left = 32
    Height = 14
    Top = 79
    Width = 31
    Caption = 'Oil %:'
    ParentColor = False
    OnClick = Label1Click
  end
  object DbOil: TDBEdit
    Left = 80
    Height = 21
    Top = 72
    Width = 80
    DataField = 'OIL'
    DataSource = Datasource1
    CharCase = ecNormal
    MaxLength = 0
    TabOrder = 2
    OnChange = DbOilChange
  end
  object DbMaut: TDBEdit
    Left = 80
    Height = 21
    Top = 44
    Width = 80
    DataField = 'MAUT'
    DataSource = Datasource1
    CharCase = ecNormal
    MaxLength = 0
    TabOrder = 1
    OnChange = DbMautChange
  end
  object DbFattura: TDBEdit
    Left = 80
    Height = 21
    Top = 100
    Width = 80
    DataField = 'NUMERO'
    DataSource = Datasource1
    CharCase = ecNormal
    MaxLength = 8
    TabOrder = 3
    OnChange = DbOilChange
  end
  object Label4: TLabel
    Left = 32
    Height = 14
    Top = 104
    Width = 41
    Caption = 'Fattura:'
    ParentBidiMode = False
    ParentColor = False
    OnClick = Label1Click
  end
  object ProgressBar1: TProgressBar
    Left = 8
    Height = 21
    Top = 192
    Width = 571
    TabOrder = 4
  end
  object Label5: TLabel
    Left = 184
    Height = 14
    Top = 51
    Width = 62
    Caption = 'Granvolume:'
    ParentColor = False
    OnClick = Label1Click
  end
  object Label6: TLabel
    Left = 178
    Height = 14
    Top = 79
    Width = 68
    Caption = 'Cons.su isola:'
    ParentColor = False
    OnClick = Label1Click
  end
  object DbIsola: TDBEdit
    Left = 256
    Height = 21
    Top = 72
    Width = 80
    DataField = 'ISOLA'
    DataSource = Datasource1
    CharCase = ecNormal
    MaxLength = 0
    TabOrder = 5
    OnChange = DbIsolaChange
  end
  object DbVolume: TDBEdit
    Left = 256
    Height = 21
    Top = 44
    Width = 80
    DataField = 'GRANVOLUME'
    DataSource = Datasource1
    CharCase = ecNormal
    MaxLength = 0
    TabOrder = 6
    OnChange = DbVolumeChange
  end
  object DbPercorso: TFileNameEdit
    Left = 80
    Height = 21
    Top = 16
    Width = 448
    DialogOptions = []
    FilterIndex = 0
    HideDirectories = False
    ButtonWidth = 23
    NumGlyphs = 0
    MaxLength = 0
    TabOrder = 7
  end
  object IBConnection1: TIBConnection
    Connected = True
    LoginPrompt = False
    DatabaseName = 'D:\EuroService\Archivi\TRAITORR.FDB'
    KeepConnection = False
    Password = 'masterkey'
    Transaction = SQLTransaction1
    UserName = 'SYSDBA'
    HostName = 'localhost'
    LogEvents = []
    left = 144
    top = 136
  end
  object SQLTransaction1: TSQLTransaction
    Active = True
    Action = caNone
    Database = IBConnection1
    left = 176
    top = 136
  end
  object SQLQuery1: TSQLQuery
    IndexName = 'DEFAULT_ORDER'
    FieldDefs = <   
      item
        Name = 'PERCORSO'
        DataType = ftString
        Precision = -1
        Size = 255
      end   
      item
        Name = 'MAUT'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'OIL'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'NUMERO'
        DataType = ftString
        Precision = -1
        Size = 8
      end   
      item
        Name = 'GRANVOLUME'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ISOLA'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'DADATA'
        DataType = ftDate
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ADATA'
        DataType = ftDate
        Precision = -1
        Size = 0
      end   
      item
        Name = 'PATHFATT'
        DataType = ftString
        Precision = -1
        Size = 150
      end   
      item
        Name = 'UTENTE'
        DataType = ftString
        Precision = -1
        Size = 10
      end   
      item
        Name = 'DANUM'
        DataType = ftLargeint
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANUM'
        DataType = ftLargeint
        Precision = -1
        Size = 0
      end   
      item
        Name = 'EMAIL'
        DataType = ftSmallint
        Precision = -1
        Size = 0
      end   
      item
        Name = 'DEFINITIVO'
        DataType = ftSmallint
        Precision = -1
        Size = 0
      end>
    Active = True
    AfterOpen = SQLQuery1AfterOpen
    Database = IBConnection1
    Transaction = SQLTransaction1
    SQL.Strings = (
      'select *'
      'from PARAMETRI'
    )
    Params = <>
    UpdateMode = upWhereAll
    left = 208
    top = 136
  end
  object Datasource1: TDatasource
    DataSet = SQLQuery1
    left = 240
    top = 136
  end
  object ODBCConnection1: TODBCConnection
    Connected = True
    LoginPrompt = False
    KeepConnection = False
    Password = 'STET72'
    Transaction = SQLTransaction2
    UserName = 'TIBERI'
    LogEvents = []
    FileDSN = 'C:\Programmi\File comuni\ODBC\Data Sources\DSNas400.dsn'
    left = 8
    top = 136
  end
  object SQLTransaction2: TSQLTransaction
    Active = True
    Action = caNone
    Database = ODBCConnection1
    left = 40
    top = 136
  end
  object SQLQuery2: TSQLQuery
    IndexName = 'DEFAULT_ORDER'
    FieldDefs = <   
      item
        Name = 'ANAANU'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANATIP'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANACOD'
        DataType = ftFixedChar
        Precision = -1
        Size = 6
      end   
      item
        Name = 'ANARAG'
        DataType = ftFixedChar
        Precision = -1
        Size = 35
      end   
      item
        Name = 'ANARA2'
        DataType = ftFixedChar
        Precision = -1
        Size = 15
      end   
      item
        Name = 'ANAIND'
        DataType = ftFixedChar
        Precision = -1
        Size = 35
      end   
      item
        Name = 'ANACAP'
        DataType = ftFixedChar
        Precision = -1
        Size = 5
      end   
      item
        Name = 'ANALOC'
        DataType = ftFixedChar
        Precision = -1
        Size = 25
      end   
      item
        Name = 'ANAPRV'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANANAZ'
        DataType = ftFixedChar
        Precision = -1
        Size = 4
      end   
      item
        Name = 'ANAPIV'
        DataType = ftFixedChar
        Precision = -1
        Size = 16
      end   
      item
        Name = 'ANARIC'
        DataType = ftFixedChar
        Precision = -1
        Size = 10
      end   
      item
        Name = 'ANATCO'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANACOC'
        DataType = ftFixedChar
        Precision = -1
        Size = 6
      end   
      item
        Name = 'ANAFN1'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFN2'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFN3'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFN4'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'LIGCOD'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'LIGFCD'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFIL'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFAT'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANACDI'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAACQ'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANAPER'
        DataType = ftFixedChar
        Precision = -1
        Size = 20
      end   
      item
        Name = 'ANATEL'
        DataType = ftFixedChar
        Precision = -1
        Size = 15
      end   
      item
        Name = 'ANATEX'
        DataType = ftFixedChar
        Precision = -1
        Size = 20
      end   
      item
        Name = 'ANAFAX'
        DataType = ftFixedChar
        Precision = -1
        Size = 15
      end   
      item
        Name = 'ANAUTX'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'PAGCOD'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANAVCO'
        DataType = ftFixedChar
        Precision = -1
        Size = 8
      end   
      item
        Name = 'ANADIF'
        DataType = ftFixedChar
        Precision = -1
        Size = 6
      end   
      item
        Name = 'ANAESE'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAPAT'
        DataType = ftFixedChar
        Precision = -1
        Size = 10
      end   
      item
        Name = 'DOGUFF'
        DataType = ftFixedChar
        Precision = -1
        Size = 6
      end   
      item
        Name = 'DOGDES'
        DataType = ftFixedChar
        Precision = -1
        Size = 30
      end   
      item
        Name = 'ANAANT'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANACOS'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANARIT'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANATIV'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANAAGE'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANAGRU'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANACON'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANARUP'
        DataType = ftFixedChar
        Precision = -1
        Size = 25
      end   
      item
        Name = 'ANAFN5'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFN6'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAVIN'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANAMEC'
        DataType = ftFixedChar
        Precision = -1
        Size = 8
      end   
      item
        Name = 'ANAATT'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANAFA1'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANAFA2'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANAAQC'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANANUA'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFES'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANACPM'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANAF07'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAF08'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAF09'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAF10'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANARAE'
        DataType = ftFixedChar
        Precision = -1
        Size = 35
      end   
      item
        Name = 'ANAFGT'
        DataType = ftFixedChar
        Precision = -1
        Size = 1
      end   
      item
        Name = 'ANAFIG'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANAMAR'
        DataType = ftFixedChar
        Precision = -1
        Size = 3
      end   
      item
        Name = 'ANADAT'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANASIG'
        DataType = ftFixedChar
        Precision = -1
        Size = 10
      end   
      item
        Name = 'ANAEDG'
        DataType = ftFixedChar
        Precision = -1
        Size = 5
      end   
      item
        Name = 'ANAFAP'
        DataType = ftFixedChar
        Precision = -1
        Size = 2
      end   
      item
        Name = 'ANNUKM'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end   
      item
        Name = 'ANACUK'
        DataType = ftFixedChar
        Precision = -1
        Size = 10
      end   
      item
        Name = 'ANAINE'
        DataType = ftFixedChar
        Precision = -1
        Size = 35
      end   
      item
        Name = 'ANALOE'
        DataType = ftFixedChar
        Precision = -1
        Size = 25
      end>
    Active = True
    AutoCalcFields = False
    Database = ODBCConnection1
    Transaction = SQLTransaction2
    SQL.Strings = (
      '     select * from mcmftraftr.anacom'
    )
    Params = <>
    left = 72
    top = 136
  end
  object Datasource2: TDatasource
    DataSet = SQLQuery2
    left = 104
    top = 136
  end
  object frDBDataSet1: TfrDBDataSet
    DataSet = SQLQuery3
    left = 352
    top = 136
  end
  object frReport1: TfrReport
    Dataset = frDBDataSet1
    InitialZoom = pzDefault
    Options = []
    PreviewButtons = [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbHelp, pbExit]
    DataType = dtDataSet
    left = 376
    top = 96
    ReportForm = {
      19000000
    }
  end
  object SQLQuery3: TSQLQuery
    FieldDefs = <   
      item
        Name = 'segnacollo'
        DataType = ftString
        Precision = -1
        Size = 30
      end   
      item
        Name = 'importo'
        DataType = ftFloat
        Precision = -1
        Size = 0
      end>
    Database = IBConnection1
    Transaction = SQLTransaction1
    SQL.Strings = (
      'select * from SALTATI'
    )
    Params = <>
    left = 320
    top = 136
  end
  object frBarCodeObject1: TfrBarCodeObject
    left = 408
    top = 96
  end
  object OpenDialog1: TOpenDialog
    FilterIndex = 0
    left = 280
    top = 136
  end
  object frDBDataSet2: TfrDBDataSet
    DataSet = SQLQuery1
    left = 384
    top = 136
  end
end
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 04:32:50 pm
Avevo capito un altra cosa. Prima di aprire il report prova a scrivere

SQLQuery1.Refresh;

Dove SQLQuery1 è il nome del tuo oggetto query.
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 04:40:11 pm
Mi da questo errore.
La query e' SQLQuery3, quella creata sulla form.
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 04:46:27 pm
Sembrerebbe che la query è stata chiusa con il comando

SQLQuery3.Close;

Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 05:03:12 pm
no, la query e' ancora attiva con la creazione della form con lazarus.
Comunque ho inserito queste righe al posto del refresh

Codice: [Seleziona]

  SQLQUERY3.close;
  SQLQUERY3.SQL.Text := 'SELECT * FROM saltati';
  SQLQUERY3.OPEN;

  frreport1.FileName:=IncludeTrailingPathDelimiter(GetCurrentDir) + 'gls.lrf';
  frReport1.LoadFromFile(IncludeTrailingPathDelimiter(GetCurrentDir) + 'gls.lrf');
  frReport1.ShowReport;
                                     

ed ha funzionato.

Mille grazie.
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 14, 2012, 05:04:59 pm
Perfetto, tanto il comando refresh penso faccia la stessa cosa!  ;)
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 05:58:34 pm
Chiedo scusa, pensavo avesse funzionato invece il problema e' rimasto.
Quando passa la seconda volta sull'evento click mi fa ancora vedere il primo report senza aggiornare i dati
Titolo: Re:problema di refresh su lazreport
Inserito da: tiberi72 - Febbraio 14, 2012, 11:41:33 pm
Ho scoperto qual'e' il problema:
bisogna effettuare una commit sulla transazione creata sulla tabella SQLQUERY3.
In firebird alcuni tipi di transazione non fanno visualizzare modifiche fino a quando non viene effettuata la commit.
Titolo: Re:problema di refresh su lazreport
Inserito da: xinyiman - Febbraio 15, 2012, 08:39:08 am
Perfetto grazie dell'informazione.  :)